Not able to run an app on Android - java

I am parsing Json data from a URL in Android. I am not getting any error while executing. But nothing is coming up.
Here is my MainActivity.Java code:
public class MainActivity extends ListActivity {
/** Called when the activity is first created. */
#SuppressWarnings({ "rawtypes", "unchecked" })
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,
this.fetchTwitterPublicTimeline()));
}
public ArrayList<String> fetchTwitterPublicTimeline()
{
ArrayList<String> listItems = new ArrayList<String>();
try {
URL twitter = new URL(
"http://twitter.com/statuses/public_timeline.json");
URLConnection tc = twitter.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
tc.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
JSONArray ja = new JSONArray(line);
for (int i = 0; i < ja.length(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
listItems.add(jo.getString("text"));
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return listItems;
}
}
And this is my manifest.xml content:
package="com.example.harsh"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity"
android:label="Android List View">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
This is the R.java file:
package com.example.harsh;
public final class R {
public static final class attr {
}
public static final class dimen {
public static final int activity_horizontal_margin=0x7f040000;
public static final int activity_vertical_margin=0x7f040001;
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int action_settings=0x7f080000;
}
public static final class layout {
public static final int activity_main=0x7f030000;
}
public static final class menu {
public static final int main=0x7f070000;
}
public static final class string {
public static final int action_settings=0x7f050001;
public static final int app_name=0x7f050000;
public static final int hello_world=0x7f050002;
}
public static final class style {public static final int
activity_horizontal_margin=0x7f040000;
public static final int activity_vertical_margin=0x7f040001;
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int action_settings=0x7f080000;
}
public static final class layout {
public static final int activity_main=0x7f030000;
}
public static final class menu {
public static final int main=0x7f070000;
}
public static final class string {
public static final int action_settings=0x7f050001;
public static final int app_name=0x7f050000;
public static final int hello_world=0x7f050002;
}
public static final class style {
public static final int AppBaseTheme=0x7f060000;
public static final int AppTheme=0x7f060001;
}
}
While running it nothing is coming up after this:
[2013-10-15 23:37:39 - FirstApp] adb is running normally.
[2013-10-15 23:37:39 - FirstApp] Performing com.example.harsh.MainActivity activity launch
[2013-10-15 23:37:40 - FirstApp] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'abc'
[2013-10-15 23:37:40 - FirstApp] Uploading FirstApp.apk onto device 'emulator-5554'
[2013-10-15 23:37:46 - FirstApp] Installing FirstApp.apk...
[2013-10-15 23:38:26 - FirstApp] Success!
So i am not able to figure out what is the problem.

It looks like you're doing network/internet access on the main UI thread by calling your fetchTwitterPublicTimeline method in the activities onCreate. This will throw an exception in API levels newer than Honeycomb.
You should move that to an AsyncTask or background thread that is kicked off in the onCreate method and then fill your adapter when the AsyncTask completes and has data.

Related

How do I combine this two application class for Android Studio?

I have two application class which I want to combine in one, but provides two function, but I want it only one class so that I can call it on the application class in my manifest and get the App to produce both functions since i can not have two classes called on the application class in my manifest file in android studo.
I would like to put the AppController class in the App.Java class
Where I am confused is how to combine it since both extends different classes which java does not permit extending two classes in one.
Below is the App.java class
public class App extends MultiDexApplication implements Constants {
public static final String TAG = App.class.getSimpleName();
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
private static App mInstance;
private ArrayList<Feeling> feelingsList;
private ArrayList<BaseGift> giftsList;
private SharedPreferences sharedPref;
private String username, fullname, accessToken, gcmToken = "", fb_id = "", photoUrl, coverUrl, area = "", country = "", city = "";
private Double lat = 0.000000, lng = 0.000000;
private long id;
private int state, allowRewardedAds = 1, admob = 1, ghost, pro, verify, balance, allowShowMyInfo, allowShowMyFriends, allowShowMyGallery, allowShowMyGifts, allowGalleryComments, allowComments, allowMessages, allowLikesGCM, allowCommentsGCM, allowFollowersGCM, allowGiftsGCM, allowMessagesGCM, allowCommentReplyGCM, errorCode, currentChatId = 0, notificationsCount = 0, messagesCount = 0, guestsCount = 0, newFriendsCount = 0;
#Override
public void onCreate() {
super.onCreate();
mInstance = this;
FirebaseApp.initializeApp(this);
sharedPref = this.getSharedPreferences(getString(R.string.settings_file), Context.MODE_PRIVATE);
this.readData();
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
try {
ProviderInstaller.installIfNeeded(this);
} catch (Exception e) {
e.getMessage();
}
}
}
// NB; I have some more codes in here which i am unable to put in full here.
}
}
Then this this the second class AppController.java
public class AppController extends Application {
private static Context mContext;
private static String mAppUrl;
public static MediaPlayer player;
public static Activity currentActivity;
#Override
public void onCreate() {
super.onCreate();
setContext(getApplicationContext());
mAppUrl = Constant.PLAYSTORE_URL + mContext.getPackageName();
setTelephoneListener();
player = new MediaPlayer();
mediaPlayerInitializer();
//AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
public static void mediaPlayerInitializer(){
try {
player = MediaPlayer.create(getAppContext(), R.raw.snd_bg);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setLooping(true);
player.setVolume(1f, 1f);
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
public static String getAppUrl() {
return mAppUrl;
}
private static void setContext(Context context) {
mContext = context;
}
public static Context getAppContext() {
return mContext;
}
public static void playSound()
{
try {
if (SettingsPreferences.getMusicEnableDisable(mContext)&&!player.isPlaying()) {
player.start();
}else{
}
} catch (IllegalStateException e) {
e.printStackTrace();
mediaPlayerInitializer();
player.start();
}
}
public static void StopSound() {
if (player.isPlaying()) {
player.pause();
}
}
private void setTelephoneListener() {
PhoneStateListener phoneStateListener = new PhoneStateListener() {
#Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
StopSound();
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
StopSound();
}
super.onCallStateChanged(state, incomingNumber);
}
};
TelephonyManager telephoneManager = (TelephonyManager) getAppContext().getSystemService(Context.TELEPHONY_SERVICE);
if (telephoneManager != null) {
telephoneManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
static
{
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}
Just Extend Your "AppController" class to "App" class. No need to do extra other work.
Like Below.
public class AppController extends App {
......
}
MulitdexApplication extends Application.
You could change your AppController to:
public class AppController extends MulitdexApplication
and then your App to
public class App extends AppController implements Constants

Flutter - Platform Exception: Cannot add a null child view to a ViewGroup

I am trying to show a Banner Ad from native java code to Flutter. I've tried seeing multiple plugins to write my code however when my app debugs it always shows me the error - Unhandled Exception: PlatformException(error, Cannot add a null child view to a ViewGroup, null, java.lang.IllegalArgumentException: Cannot add a null child view to a ViewGroup
Here's my Java code using PlatformViewFactory -
public class BannerFactory extends PlatformViewFactory {
private final BinaryMessenger messenger;
public BannerFactory(BinaryMessenger messenger) {
super(StandardMessageCodec.INSTANCE);
this.messenger = messenger;
}
#Override
public PlatformView create(Context context, int viewId, Object args) {
return new BannerUtil(context, this.messenger, viewId, (HashMap) args);
}
}
This is my actual BannerUtil class that contains the callbacks for my Banner Ad.
public class BannerUtil implements PlatformView {
// private FrameLayout layout;
private static final String TAG = "BannerUtil";
private int height;
private int width;
private MethodChannel channel;
private int size;
private String adUnitId;
private String placementId;
private boolean closeButton;
private int refreshTime;
private MBBannerView mtgBannerView;
public BannerUtil(Context context, BinaryMessenger messenger, int id, HashMap args) {
try {
this.size = (int) args.get("size");
this.adUnitId = (String) args.get("adUnitId");
this.placementId = (String) args.get("placementId");
this.closeButton = (boolean) args.get("closeButton");
this.refreshTime = (int) args.get("refreshTime");
this.height = (int) args.get("height");
this.width = (int) args.get("width");
this.channel = new MethodChannel(messenger, "flutter_mintegral");
// this.layout = new FrameLayout(FlutterMintegralPlugin.activity);
mtgBannerView = new MBBannerView(FlutterMintegralPlugin.activity);
mtgBannerView.init(new BannerSize(BannerSize.DEV_SET_TYPE, width, height), placementId, adUnitId);
mtgBannerView.setAllowShowCloseBtn(closeButton);
mtgBannerView.setRefreshTime(refreshTime);
mtgBannerView.setBannerAdListener(new BannerAdListener() {
#Override
public void onLoadFailed(String msg) {
Log.e(TAG, "on load failed" + msg);
}
#Override
public void onLoadSuccessed() {
Log.e(TAG, "on load successed");
}
});
if (mtgBannerView != null) {
// this.layout.removeAllViews();
mtgBannerView.load();
// FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
// FrameLayout.LayoutParams.MATCH_PARENT);
// this.layout.addView(mtgBannerView,0,layoutParams);
// layout.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
Log.e("MintegralSDK", e.toString());
}
}
#Override
public View getView() {
return mtgBannerView;
}
#Override
public void dispose() {
//this.layout.removeAllViews();
if (mtgBannerView != null) {
mtgBannerView.release();
}
}
}
I need help as i'm unsure how to call FrameLayout from Java to call the banner ad in Flutter.
I am even registering my banner ad in my plugins main class like this -
private void RegistrarBanner(PlatformViewRegistry registry, BinaryMessenger messenger) {
registry.registerViewFactory("/Banner", new BannerFactory(messenger));
}
public static void registerWith(Registrar registrar) {
registrar.platformViewRegistry().registerViewFactory("/Banner", new
BannerFactory(registrar.messenger()));
}
#Override
public void onAttachedToEngine(#NonNull FlutterPluginBinding flutterPluginBinding) {
this.flutterPluginBinding = flutterPluginBinding;
this.RegistrarBanner(flutterPluginBinding.getPlatformViewRegistry(), flutterPluginBinding.getBinaryMessenger());
}
This is my Dart part of code (of my internal plugin) which calls AndroidView -
Container(
width: this.sizes[this.widget.size].width,
height: this.sizes[this.widget.size].height,
child: AndroidView(
viewType: '/Banner',
key: UniqueKey(),
creationParams: {
'closeButton': widget.closeButton,
'refreshTime': widget.refreshTime,
'adUnitId': widget.adUnitId,
'placementId': widget.placementId,
'size': this.sizes[this.widget.size].type,
'height': this.sizes[this.widget.size].height,
'width': this.sizes[this.widget.size].width
},
creationParamsCodec: StandardMessageCodec(),
),
);
I'm unsure as to where I'm going wrong? Can someone please help me.

android: saving json to sqlite

i'm a new bie in android and java i want to save a table from sql server(external database) to sqlite(internal database).
1. my json is not getting stored and every record is same like this "com.example.db_client.DeptTable#b3e4e9e0" when i opens the db file in sqlite browser. I don't understand what is this.
when i run my app i sometimes get this exception and sometimes i don't.
FATAL EXCEPTION: main
Process: com.example.db_client, PID: 1697
java.lang.IllegalArgumentException: Activity DeptActivity does not have a parent activity name specified. (Did you forget to add the android.support.PARENT_ACTIVITY element in your manifest?)
I really need help please look into my problem. thanks in advance.
code of database helper class
public class SqliteDB {
public static final String KEY_ID = "no";
public static final String KEY_NAME = "name";
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "SQLiteDB";
private static final String TABLE_NAME = "Department";
private static final int DATABASE_VERSION = 2;
private static final String CREATE_TABLE =
"create table departmentList (id INTEGER PRIMARY KEY, name TEXT);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public SqliteDB(Context ctx) {
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(CREATE_TABLE);
} catch (SQLException e) {
e.printStackTrace();
}
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS sample");
onCreate(db);
}
}
//---open SQLite DB---
public SqliteDB open() throws SQLException {
db = DBHelper.getWritableDatabase();
return this;
}
//---close SQLite DB---
public void close() {
DBHelper.close();
}
//---insert data into SQLite DB---
public long insert(String name) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_NAME, name);
return db.insert(TABLE_NAME, null, initialValues);
}
//---Delete All Data from table in SQLite DB---
public void deleteAll() {
db.delete(TABLE_NAME, null, null);
}
//---Get All Contacts from table in SQLite DB---
public Cursor getAllData() {
return db.query(TABLE_NAME, new String[] {KEY_NAME},
null, null, null, null, null);
}
}
code of activity class
public class DeptActivity extends Activity{
ArrayAdapter<String> adapter;
ListView listv;
Context context;
ArrayList<String> data;
SqliteDB sqlite;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dept);
sqlite = new SqliteDB(DeptActivity.this);
setupActionBar();
data = new ArrayList<String>();
listv = (ListView) findViewById(R.id.lv_dept);
context = this;
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, data);
listv.setAdapter(adapter);
Toast.makeText(this,"Loading Please Wait..",Toast.LENGTH_SHORT).show();
new AsyncLoadDeptDetails().execute();
}
public class AsyncLoadDeptDetails extends
AsyncTask<Void, JSONObject, ArrayList<DeptTable>> {
ArrayList<DeptTable> deptTable = null;
#Override
public ArrayList<DeptTable> doInBackground(Void... params) {
// TODO Auto-generated method stub
RestAPI api = new RestAPI();
try {
JSONObject jsonObj = api.GetDepartmentDetails();
JSONParser parser = new JSONParser();
Log.i( "department list", jsonObj.toString());
deptTable = parser.parseDepartment(jsonObj);
sqlite();
} catch (Exception e) {
}
return deptTable;
}
private void sqlite() {
// TODO Auto-generated method stub
sqlite.open();
for(int i=0; i<deptTable.size(); i++) {
sqlite.insert(deptTable.get(i).toString());
}
sqlite.close();
}
#Override
protected void onPostExecute(ArrayList<DeptTable> result) {
// TODO Auto-generated method stub
for (int i = 0; i < result.size(); i++) {
data.add(result.get(i).getNo() + " " + result.get(i).getName());
}
adapter.notifyDataSetChanged();
Toast.makeText(context,"Loading Completed",Toast.LENGTH_SHORT).show();
} }
and the table which i want to save in sqlite db looks like this.
no. name
1 engineering
2 finance
3 commerce
public class DeptTable {
int no;
String name;
public DeptTable(int no, String name) {
super();
this.no = no;
this.name = name;
}
code of deptTable Class
public DeptTable() {
super();
this.no=0;
this.name = null;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
code of json parser class
public class JSONParser {
public JSONParser()
{
super();
}
public ArrayList<DeptTable> parseDepartment(JSONObject object)
{
ArrayList<DeptTable> arrayList=new ArrayList<DeptTable>();
try {
JSONArray jsonArray=object.getJSONArray("Value");
JSONObject jsonObj=null;
for(int i=0;i<jsonArray.length();i++)
{
jsonObj =jsonArray.getJSONObject(i);
arrayList.add(new DeptTable(jsonObj.getInt("no"), jsonObj.getString("name")));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.d("JSONParser => parseDepartment", e.getMessage());
}
return arrayList;
}
public boolean parseUserAuth(JSONObject object)
{ boolean userAtuh=false;
try {
userAtuh = object.getBoolean("Value");
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.d("JSONParser => parseUserAuth", e.getMessage());
}
return userAtuh; }
code of manifest
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.db_client.DeptActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
enter code here
If you want to use the toString method the class has to implement the toString method otherwise it will just return the default for object with you find out is not so useful. (This "com.example.db_client.DeptTable#b3e4e9e0"). To implement it just type do like this.
#Override
public String toString() {
//What you want to return here.
}
But I'm guessing you want to add some value to the database so you want to call the getter method of your class like this.
private void sqlite() {
sqlite.open();
for(int i=0; i<deptTable.size(); i++) {
sqlite.insert(deptTable.get(i).getName());
}
sqlite.close();
}
You need to add the android:parentActivityName field to DeptActivity like this.
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.db_client.DeptActivity"
android:label="#string/app_name"
android:parentActivityName=".MainActivity">
</activity>
</application>
</manifest>

Java/Android: how do I access the ContentProvider that is declared in AndroidManifest.xml?

AndroidManifest.xml:
<provider android:authorities="com.mygame.expansion" android:exported="false" android:multiprocess="true" android:name="org.apache.cordova.xapkreader.XAPKProvider" />
I have an APEZProvider class, which comes from the Android SDK /extras folder. It extends ContentProvider.
I also have a XAPKProvider class, which extends APEZProvider:
public class XAPKProvider extends APEZProvider {
#Override public String getAuthority () {return "com.mygame.expansion";}
public int mainFileVersion = 0;
public int patchFileVersion = 0;
#Override public boolean initIfNecessary () {
if (mInit) return true;
Context ctx = getContext ();
try {
mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile (ctx, mainFileVersion, patchFileVersion);
mInit = true;
return true;
} catch (IOException e) {
e.printStackTrace ();
}
return false;
}
}
How can I access the ContentProvider object created in the AndroidManifest.xml file, so that I can modify the mainFileVersion and patchFileVersion variables?
I found another StackOverflow post that got me to the answer. I needed to override "call". For example:
ContentResolver cr = cordova.getActivity().getApplicationContext().getContentResolver();
String expansionAuthority = bundle.getString("expansion_authority", "");
cr.call (Uri.parse("content://" + expansionAuthority), "set_expansion_file_versions", null, bundle);
Then:..
#Override public Bundle call (String method, String arg, Bundle bundle) {
if (method.equals("set_expansion_file_versions")) {
mainFileVersion = bundle.getInt("main_version" , 1);
patchFileVersion = bundle.getInt("patch_version", 1);
expansionAuthority = bundle.getString("expansion_authority", "com.sample.expansion");
xmlDataReceived = true;
return null;
}
return null;
}

Start new intent on ShowcaseViews button

I was wondering how to start a new intent if the user presses a button in my Android in-app tutorial (ShowcaseViews). Here is my ShowcaseViews class:
public class ShowcaseViews {
private final List<ShowcaseView> views = new ArrayList<ShowcaseView>();
private final Activity activity;
private final int showcaseTemplateId;
private interface OnShowcaseAcknowledged {
void onShowCaseAcknowledged(ShowcaseView oldView);
}
/**
* #param activity The activity containing the views you wish to showcase
* #param showcaseTemplateLayout Must be the layout of a ShowcaseView - use this to style your showcase
*/
public ShowcaseViews(Activity activity, int showcaseTemplateLayout) {
this.activity = activity;
this.showcaseTemplateId = showcaseTemplateLayout;
}
public void addView(ItemViewProperties properties) {
ShowcaseView viewTemplate = newInstanceOfShowcaseView();
viewTemplate.setShowcaseItem(properties.itemType, properties.id, activity);
viewTemplate.setText(properties.titleResId, properties.messageResId);
setChainClickListener(viewTemplate);
views.add(viewTemplate);
}
public void addView(ViewProperties properties) {
ShowcaseView viewTemplate = newInstanceOfShowcaseView();
View v = activity.findViewById(properties.id);
viewTemplate.setShowcaseView(v);
viewTemplate.setText(properties.titleResId, properties.messageResId);
setChainClickListener(viewTemplate);
views.add(viewTemplate);
}
private ShowcaseView newInstanceOfShowcaseView() {
return (ShowcaseView) activity.getLayoutInflater().inflate(showcaseTemplateId, null);
}
private void setChainClickListener(final ShowcaseView viewTemplate) {
viewTemplate.overrideButtonClick(new View.OnClickListener() {
#Override
public void onClick(View v) {
acknowledgedListener.onShowCaseAcknowledged(viewTemplate);
}
});
}
private OnShowcaseAcknowledged acknowledgedListener = new OnShowcaseAcknowledged() {
#Override
public void onShowCaseAcknowledged(ShowcaseView oldView) {
oldView.hide();
show();
}
};
/**
* Showcases will be shown in the order they where added, continuing when the button is pressed
*/
public void show() {
if (views.isEmpty()) {
return;
}
final ShowcaseView view = views.get(0);
((ViewGroup) activity.getWindow().getDecorView()).addView(view);
views.remove(0);
}
/**
* Used for views on the ActionBar
*/
public static class ItemViewProperties extends ViewProperties {
public static final int ID_SPINNER = 0;
public static final int ID_TITLE = 0;
protected final int itemType;
public ItemViewProperties(int id, int titleResId, int messageResId, int itemType) {
super(id, titleResId, messageResId);
this.itemType = itemType;
}
}
/**
* Used for all views except those on the ActionBar
*/
public static class ViewProperties {
protected final int titleResId;
protected final int messageResId;
protected final int id;
public ViewProperties(int id, int titleResId, int messageResId) {
this.id = id;
this.titleResId = titleResId;
this.messageResId = messageResId;
}
}
}
Here is my MainActivity class:
public void showcaseSecondActivity() {
ShowcaseViews views = new ShowcaseViews(CameraTestActivity.this, R.layout.view_showcase);
views.addView(new ShowcaseViews.ItemViewProperties(0, R.string.showcase_main_spinner_title, R.string.showcase_main_spinner_message, ShowcaseView.ITEM_ACTION_HOME));
Intent intent = new Intent(CameraTestActivity.this, UserSettingsActivity.class);
views.show();
}
Here is my view_showcase XML file:
<?xml version="1.0" encoding="utf-8"?>
<!-- This is our ShowCase template that we will use
whenever we want to showcase an item.
Here we can customise the colors of the showcase. -->
<com.rohit.ShowcaseView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:showcaseview="http://schemas.android.com/apk/res/com.rohit"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
showcaseview:sv_backgroundColor="#color/showcase_background"
showcaseview:sv_buttonText="#string/showcase_button_ok" />
If I add startActivity(intent) after views.show() in my MainActivity class, it doesn't even show the dialog and goes straight to the intent. I want to open the activity AFTER the user has clicked the button. I don't know to proceed. I am quite new to this and I have searched all over SO and Google. Any help regarding this problem would be appreciated.
showcaseView.setOnShowcaseEventListener(new OnShowcaseEventListener() {
#Override
public void onShowcaseViewShow(ShowcaseView arg0) { }
#Override
public void onShowcaseViewHide(ShowcaseView arg0) {
Intent i = new Intent(SignIn.this,MainFragmentActivity.class);
startActivity(i);
}
#Override
public void onShowcaseViewDidHide(ShowcaseView arg0) { }
});

Categories