List of usage examples for android.os Bundle putInt
public void putInt(@Nullable String key, int value)
From source file:com.gelakinetic.mtgfam.activities.MainActivity.java
public void showDialogFragment(final int id) { // DialogFragment.show() will take care of adding the fragment // in a transaction. We also want to remove any currently showing // dialog, so make our own transaction and take care of that here. this.showContent(); FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction(); Fragment prev = getSupportFragmentManager().findFragmentByTag(FamiliarFragment.DIALOG_TAG); if (prev != null) { ft.remove(prev);/*from w ww . jav a2s . co m*/ } // Create and show the dialog. FamiliarDialogFragment newFragment = new FamiliarDialogFragment() { @Override public void onDismiss(DialogInterface mDialog) { super.onDismiss(mDialog); if (bounceMenu) { getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); bounceMenu = false; Runnable r = new Runnable() { @Override public void run() { long timeStarted = System.currentTimeMillis(); Message msg = Message.obtain(); msg.arg1 = OPEN; bounceHandler.sendMessage(msg); while (System.currentTimeMillis() < (timeStarted + 1500)) { ; } msg = Message.obtain(); msg.arg1 = CLOSE; bounceHandler.sendMessage(msg); runOnUiThread(new Runnable() { @Override public void run() { getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED); } }); } }; Thread t = new Thread(r); t.start(); } } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { switch (id) { case DONATEDIALOG: { AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity()); builder.setTitle(R.string.main_donate_dialog_title); builder.setNeutralButton(R.string.dialog_thanks_anyway, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); LayoutInflater inflater = this.getActivity().getLayoutInflater(); View dialoglayout = inflater.inflate(R.layout.about_dialog, (ViewGroup) findViewById(R.id.dialog_layout_root)); TextView text = (TextView) dialoglayout.findViewById(R.id.aboutfield); text.setText(ImageGetterHelper.jellyBeanHack(getString(R.string.main_donate_text))); text.setMovementMethod(LinkMovementMethod.getInstance()); text.setTextSize(15); ImageView paypal = (ImageView) dialoglayout.findViewById(R.id.imageview1); paypal.setImageResource(R.drawable.paypal); paypal.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse( "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=SZK4TAH2XBZNC&lc=US&item_name=MTG%20Familiar¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted")); startActivity(myIntent); } }); ((ImageView) dialoglayout.findViewById(R.id.imageview2)).setVisibility(View.GONE); builder.setView(dialoglayout); return builder.create(); } case ABOUTDIALOG: { AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity()); // You have to catch the exception because the package stuff is all // run-time if (pInfo != null) { builder.setTitle(getString(R.string.main_about) + " " + getString(R.string.app_name) + " " + pInfo.versionName); } else { builder.setTitle(getString(R.string.main_about) + " " + getString(R.string.app_name)); } builder.setNeutralButton(R.string.dialog_thanks, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); LayoutInflater inflater = this.getActivity().getLayoutInflater(); View dialoglayout = inflater.inflate(R.layout.about_dialog, (ViewGroup) findViewById(R.id.dialog_layout_root)); TextView text = (TextView) dialoglayout.findViewById(R.id.aboutfield); text.setText(ImageGetterHelper.jellyBeanHack(getString(R.string.main_about_text))); text.setMovementMethod(LinkMovementMethod.getInstance()); builder.setView(dialoglayout); return builder.create(); } case CHANGELOGDIALOG: { AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity()); if (pInfo != null) { builder.setTitle(getString(R.string.main_whats_new_in_title) + " " + pInfo.versionName); } else { builder.setTitle(R.string.main_whats_new_title); } builder.setNeutralButton(R.string.dialog_enjoy, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.setMessage(ImageGetterHelper.jellyBeanHack(getString(R.string.main_whats_new_text))); return builder.create(); } default: { savedInstanceState.putInt("id", id); return super.onCreateDialog(savedInstanceState); } } } }; newFragment.show(ft, FamiliarFragment.DIALOG_TAG); }
From source file:com.if3games.chessonline.DroidFish.java
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if (isSinglePlayer) { if (ctrl != null) { byte[] data = ctrl.toByteArray(); outState.putByteArray("gameState", data); outState.putInt("gameStateVersion", 3); }//from w w w.jav a 2 s. c o m } }
From source file:com.example.android.navigationdrawerexample.Controller.PilihanController.java
private void selectItem(int position) { // update the main content by replacing fragments /*Fragment fragment = new PlanetFragment();*/ fragment = null;// www.ja va 2s.c om Bundle args = new Bundle(); switch (position) { case 0: fragment = new Fragment() { @Override public void onResume() { super.onResume(); new GetAllJadwalTask(PilihanController.this).execute(username); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); View view = inflater.inflate(R.layout.list_jadwal, container, false); GetAllJadwalListView = (ExpandableListView) view.findViewById(R.id.GetAllJadwalListView); ImageView buat = (ImageView) view.findViewById(R.id.button); //Button pilihan = (Button) view.findViewById(R.id.button9); if (role == 0) buat.setVisibility(View.GONE); else buat.setVisibility(View.VISIBLE); new GetAllJadwalTask(PilihanController.this).execute(username); GetAllJadwalListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { GetAllJadwalListView.expandGroup(groupPosition); return true; } }); GetAllJadwalListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { try { //Toast.makeText(getApplicationContext(), listDataChild2.get(listDataHeader2.get(groupPosition)).get(childPosition).toString(), Toast.LENGTH_LONG).show(); int jadwalp = listDataChild2.get(listDataHeader2.get(groupPosition)) .get(childPosition).getInt("Id"); int kelasp = listDataChild2.get(listDataHeader2.get(groupPosition)) .get(childPosition).getInt("Id_kelas"); //// JSONObject mahasiswaClicked = jsonArray.getJSONObject(groupPosition+childPosition); //// int jadwalp = mahasiswaClicked.getInt("Id"); //// int kelasp = mahasiswaClicked.getInt("Id_kelas"); Intent showDetails = new Intent(getActivity(), JadwalController.class); showDetails.putExtra("JadwalID", jadwalp); showDetails.putExtra("KelasID", kelasp); showDetails.putExtra("Username", username); showDetails.putExtra("View", "detailJadwal"); startActivity(showDetails); } catch (JSONException e) { e.printStackTrace(); //Toast.makeText(getApplicationContext(), "lala masuk ex", Toast.LENGTH_LONG).show(); } return false; } }); buat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent showDetails = new Intent(getActivity(), JadwalController.class); //asumsi username gak null showDetails.putExtra("Username", username); showDetails.putExtra("View", "createJadwal"); startActivity(showDetails); } }); return view; } }; args.putString(FragmentOne.ITEM_NAME, dataList.get(position).getItemName()); args.putInt(FragmentOne.IMAGE_RESOURCE_ID, dataList.get(position).getImgResID()); args.putInt("role", 2); break; case 1: fragment = new RoleFragment(); args.putInt("role", 1); break; case 2: fragment = new Fragment() { @Override public void onResume() { super.onResume(); new GetAllEnrollTask(PilihanController.this).execute(username); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); view = inflater.inflate(R.layout.list_enroll, container, false); //GetAllEnrollListView = (ListView) view.findViewById(R.id.GetAllJadwalListView); ImageView enroll = (ImageView) view.findViewById(R.id.button); expListView = (ExpandableListView) view.findViewById(R.id.lvExp); new GetAllEnrollTask(PilihanController.this).execute(username); expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { //asumsikan kalo dipencet bisa ngeluarin infromasi asistennya //viewnya di view_profile_personal //kelasnya inten, nah loh pake controller mana nih?? //asumsikan gue punya kelas ProfileAsdos.java String userAsdos = listDataChild.get(listDataHeader.get(groupPosition)) .get(childPosition); Intent showDetails = new Intent(getActivity(), MenjabatController.class); showDetails.putExtra("Username", userAsdos); startActivity(showDetails); return false; } }); enroll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent showDetails = new Intent(getActivity(), EnrollController.class); showDetails.putExtra("Username", username); startActivity(showDetails); } }); return view; } }; args.putInt("role", 0); break; case 3: fragment = new Fragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); View view = inflater.inflate(R.layout.choose_forum, container, false); Button buttonForumReply = (Button) view.findViewById(R.id.choose_forum_1); Button buttonForumForum = (Button) view.findViewById(R.id.choose_forum_2); Button buttonForumPolling = (Button) view.findViewById(R.id.choose_forum_3); buttonForumReply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), ForumQA.class); intent.putExtra("Username", username); startActivity(intent); } }); buttonForumForum.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), ForumRequest.class); intent.putExtra("Username", username); startActivity(intent); } }); buttonForumPolling.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), ForumPolling.class); intent.putExtra("Username", username); startActivity(intent); } }); return view; } }; args.putInt("role", 3); break; case 4: //ProfileController profileController2 = new ProfileController(username); if (role == 2) { fragment = new Fragment() { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); view = inflater.inflate(R.layout.admin, container, false); //GetAllEnrollListView = (ListView) view.findViewById(R.id.GetAllJadwalListView); Button kelas = (Button) view.findViewById(R.id.button9); Button role = (Button) view.findViewById(R.id.button10); Button database = (Button) view.findViewById(R.id.button11); Button forum = (Button) view.findViewById(R.id.button12); kelas.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent showDetails = new Intent(getActivity(), KelasController.class); //asumsi username gak null showDetails.putExtra("Username", username); showDetails.putExtra("View", "listKelas"); startActivity(showDetails); } }); role.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent showDetails = new Intent(getActivity(), RoleController.class); //asumsi username gak null showDetails.putExtra("Username", username); startActivity(showDetails); } }); database.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent showDetails = new Intent(getActivity(), Database.class); startActivity(showDetails); } }); forum.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent showDetails = new Intent(getActivity(), AdminThread.class); startActivity(showDetails); } }); return view; } }; } else { fragment = new FragmentOne(); Toast.makeText(getApplicationContext(), "Hei Anda Bukan Admin", Toast.LENGTH_LONG).show(); } args.putInt("role", 4); break; case 5: session.logoutUser(); finish(); return; } /*args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);*/ fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:android.content.pm.PackageParser.java
private Bundle parseMetaData(Resources res, XmlPullParser parser, AttributeSet attrs, Bundle data, String[] outError) throws XmlPullParserException, IOException { TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestMetaData); if (data == null) { data = new Bundle(); }/*from ww w. j av a 2s . c om*/ String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); if (name == null) { outError[0] = "<meta-data> requires an android:name attribute"; sa.recycle(); return null; } name = name.intern(); TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_resource); if (v != null && v.resourceId != 0) { //Slog.i(TAG, "Meta data ref " + name + ": " + v); data.putInt(name, v.resourceId); } else { v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_value); //Slog.i(TAG, "Meta data " + name + ": " + v); if (v != null) { if (v.type == TypedValue.TYPE_STRING) { CharSequence cs = v.coerceToString(); data.putString(name, cs != null ? cs.toString().intern() : null); } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { data.putBoolean(name, v.data != 0); } else if (v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT) { data.putInt(name, v.data); } else if (v.type == TypedValue.TYPE_FLOAT) { data.putFloat(name, v.getFloat()); } else { if (!RIGID_PARSER) { Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription()); } else { outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; data = null; } } } else { outError[0] = "<meta-data> requires an android:value or android:resource attribute"; data = null; } } sa.recycle(); XmlUtils.skipCurrentTag(parser); return data; }
From source file:com.irccloud.android.activity.MainActivity.java
public void onIRCEvent(int what, Object obj) { super.onIRCEvent(what, obj); Integer event_bid = 0;//from w ww . j a v a 2 s .c om final IRCCloudJSONObject event; final Object o = obj; switch (what) { case NetworkConnection.EVENT_DEBUG: runOnUiThread(new Runnable() { @Override public void run() { errorMsg.setVisibility(View.VISIBLE); errorMsg.setText(o.toString()); } }); break; case NetworkConnection.EVENT_PROGRESS: final float progress = (Float) obj; if (progressBar.getProgress() < progress) { runOnUiThread(new Runnable() { @Override public void run() { progressBar.setIndeterminate(false); progressBar.setProgress((int) progress); } }); } break; case NetworkConnection.EVENT_BACKLOG_START: runOnUiThread(new Runnable() { @Override public void run() { progressBar.setProgress(0); } }); break; case NetworkConnection.EVENT_RENAMECONVERSATION: if (buffer != null && (Integer) obj == buffer.bid) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); } }); } break; case NetworkConnection.EVENT_CHANNELTOPICIS: event = (IRCCloudJSONObject) obj; if (buffer != null && buffer.cid == event.cid() && buffer.name.equalsIgnoreCase(event.getString("chan"))) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); show_topic_popup(); } }); } break; case NetworkConnection.EVENT_LINKCHANNEL: event = (IRCCloudJSONObject) obj; if (event != null && cidToOpen == event.cid() && event.has("invalid_chan") && event.has("valid_chan") && event.getString("invalid_chan").equalsIgnoreCase(bufferToOpen)) { bufferToOpen = event.getString("valid_chan"); obj = BuffersDataSource.getInstance().getBuffer(event.bid()); } else { bufferToOpen = null; return; } case NetworkConnection.EVENT_MAKEBUFFER: BuffersDataSource.Buffer b = (BuffersDataSource.Buffer) obj; if (cidToOpen == b.cid && (bufferToOpen == null || (b.name.equalsIgnoreCase(bufferToOpen) && (buffer == null || !bufferToOpen.equalsIgnoreCase(buffer.name))))) { server = null; final int bid = b.bid; runOnUiThread(new Runnable() { @Override public void run() { onBufferSelected(bid); } }); bufferToOpen = null; cidToOpen = -1; } break; case NetworkConnection.EVENT_OPENBUFFER: event = (IRCCloudJSONObject) obj; try { bufferToOpen = event.getString("name"); cidToOpen = event.cid(); b = BuffersDataSource.getInstance().getBufferByName(cidToOpen, bufferToOpen); if (b != null && !bufferToOpen.equalsIgnoreCase(buffer.name)) { server = null; bufferToOpen = null; cidToOpen = -1; final int bid = b.bid; runOnUiThread(new Runnable() { @Override public void run() { onBufferSelected(bid); } }); } } catch (Exception e2) { e2.printStackTrace(); } break; case NetworkConnection.EVENT_CONNECTIVITY: runOnUiThread(new Runnable() { @Override public void run() { updateReconnecting(); } }); if (conn != null) { if (conn.getState() == NetworkConnection.STATE_CONNECTED) { for (EventsDataSource.Event e : pendingEvents.values()) { try { e.expiration_timer.cancel(); } catch (Exception ex) { //Task already cancellled } e.expiration_timer = null; e.failed = true; e.bg_color = R.color.error; } if (drawerLayout != null && NetworkConnection.getInstance().ready) { runOnUiThread(new Runnable() { @Override public void run() { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); getSupportActionBar().setHomeButtonEnabled(true); updateUsersListFragmentVisibility(); } }); } if (server != null && messageTxt.getText() != null && messageTxt.getText().length() > 0) { runOnUiThread(new Runnable() { @Override public void run() { sendBtn.setEnabled(true); if (Build.VERSION.SDK_INT >= 11) sendBtn.setAlpha(1); } }); } } else { runOnUiThread(new Runnable() { @Override public void run() { if (drawerLayout != null && !NetworkConnection.getInstance().ready) { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); getSupportActionBar().setHomeButtonEnabled(false); } sendBtn.setEnabled(false); if (Build.VERSION.SDK_INT >= 11) sendBtn.setAlpha(0.5f); photoBtn.setEnabled(false); if (Build.VERSION.SDK_INT >= 11) photoBtn.setAlpha(0.5f); } }); } } break; case NetworkConnection.EVENT_BANLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", event.cid()); BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(event.cid(), event.getString("channel")); if (b != null) args.putInt("bid", b.bid); args.putString("mode", "b"); args.putString("placeholder", "No bans in effect.\n\nYou can ban someone by tapping their nickname in the user list, long-pressing a message, or by using /ban."); args.putString("mask", "mask"); args.putString("list", "bans"); args.putString("title", "Ban list for " + event.getString("channel")); args.putString("event", event.toString()); ChannelModeListFragment channelModeList = (ChannelModeListFragment) getSupportFragmentManager() .findFragmentByTag("banlist"); if (channelModeList == null) { channelModeList = new ChannelModeListFragment(); channelModeList.setArguments(args); try { channelModeList.show(getSupportFragmentManager(), "banlist"); } catch (IllegalStateException e) { //App lost focus already } } else { channelModeList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_QUIETLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", event.cid()); BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(event.cid(), event.getString("channel")); if (b != null) args.putInt("bid", b.bid); args.putString("mode", "q"); args.putString("placeholder", "Empty quiet list."); args.putString("mask", "quiet_mask"); args.putString("list", "list"); args.putString("title", "Quiet list for " + event.getString("channel")); args.putString("event", event.toString()); ChannelModeListFragment channelModeList = (ChannelModeListFragment) getSupportFragmentManager() .findFragmentByTag("quietlist"); if (channelModeList == null) { channelModeList = new ChannelModeListFragment(); channelModeList.setArguments(args); try { channelModeList.show(getSupportFragmentManager(), "quietlist"); } catch (IllegalStateException e) { //App lost focus already } } else { channelModeList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_BANEXCEPTIONLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", event.cid()); BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(event.cid(), event.getString("channel")); if (b != null) args.putInt("bid", b.bid); args.putString("mode", "e"); args.putString("placeholder", "Empty exception list."); args.putString("mask", "mask"); args.putString("list", "exceptions"); args.putString("title", "Exception list for " + event.getString("channel")); args.putString("event", event.toString()); ChannelModeListFragment channelModeList = (ChannelModeListFragment) getSupportFragmentManager() .findFragmentByTag("exceptionlist"); if (channelModeList == null) { channelModeList = new ChannelModeListFragment(); channelModeList.setArguments(args); try { channelModeList.show(getSupportFragmentManager(), "exceptionlist"); } catch (IllegalStateException e) { //App lost focus already } } else { channelModeList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_INVITELIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", event.cid()); BuffersDataSource.Buffer b = BuffersDataSource.getInstance().getBufferByName(event.cid(), event.getString("channel")); if (b != null) args.putInt("bid", b.bid); args.putString("mode", "I"); args.putString("placeholder", "Empty invite list"); args.putString("mask", "mask"); args.putString("list", "list"); args.putString("title", "Invite list for " + event.getString("channel")); args.putString("event", event.toString()); ChannelModeListFragment channelModeList = (ChannelModeListFragment) getSupportFragmentManager() .findFragmentByTag("invitelist"); if (channelModeList == null) { channelModeList = new ChannelModeListFragment(); channelModeList.setArguments(args); try { channelModeList.show(getSupportFragmentManager(), "invitelist"); } catch (IllegalStateException e) { //App lost focus already } } else { channelModeList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_ACCEPTLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { if (event != null && event.cid() == buffer.cid) { Bundle args = new Bundle(); args.putInt("cid", buffer.cid); args.putString("event", event.toString()); AcceptListFragment acceptList = (AcceptListFragment) getSupportFragmentManager() .findFragmentByTag("acceptlist"); if (acceptList == null) { acceptList = new AcceptListFragment(); acceptList.setArguments(args); try { acceptList.show(getSupportFragmentManager(), "acceptlist"); } catch (IllegalStateException e) { //App lost focus already } } else { acceptList.setArguments(args); } } } }); break; case NetworkConnection.EVENT_WHOLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Bundle args = new Bundle(); args.putString("event", event.toString()); WhoListFragment whoList = (WhoListFragment) getSupportFragmentManager() .findFragmentByTag("wholist"); if (whoList == null) { whoList = new WhoListFragment(); whoList.setArguments(args); try { whoList.show(getSupportFragmentManager(), "wholist"); } catch (IllegalStateException e) { //App lost focus already } } else { whoList.setArguments(args); } } }); break; case NetworkConnection.EVENT_NAMESLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Bundle args = new Bundle(); args.putString("event", event.toString()); NamesListFragment namesList = (NamesListFragment) getSupportFragmentManager() .findFragmentByTag("nameslist"); if (namesList == null) { namesList = new NamesListFragment(); namesList.setArguments(args); try { namesList.show(getSupportFragmentManager(), "nameslist"); } catch (IllegalStateException e) { //App lost focus already } } else { namesList.setArguments(args); } } }); break; case NetworkConnection.EVENT_SERVERMAPLIST: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Bundle args = new Bundle(); args.putString("event", event.toString()); ServerMapListFragment serversList = (ServerMapListFragment) getSupportFragmentManager() .findFragmentByTag("serverslist"); if (serversList == null) { serversList = new ServerMapListFragment(); serversList.setArguments(args); try { serversList.show(getSupportFragmentManager(), "serverslist"); } catch (IllegalStateException e) { //App lost focus already } } else { serversList.setArguments(args); } } }); break; case NetworkConnection.EVENT_WHOIS: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { Bundle args = new Bundle(); args.putString("event", event.toString()); WhoisFragment whois = (WhoisFragment) getSupportFragmentManager().findFragmentByTag("whois"); if (whois == null) { whois = new WhoisFragment(); whois.setArguments(args); try { whois.show(getSupportFragmentManager(), "whois"); } catch (IllegalStateException e) { //App lost focus already } } else { whois.setArguments(args); } } }); break; case NetworkConnection.EVENT_LISTRESPONSEFETCHING: event = (IRCCloudJSONObject) obj; runOnUiThread(new Runnable() { @Override public void run() { String dialogtitle = "List of channels on " + ServersDataSource.getInstance().getServer(event.cid()).hostname; if (channelsListDialog == null) { Context ctx = MainActivity.this; final AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB); builder.setView(getLayoutInflater().inflate(R.layout.dialog_channelslist, null)); builder.setTitle(dialogtitle); builder.setNegativeButton("Close", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); channelsListDialog = builder.create(); channelsListDialog.setOwnerActivity(MainActivity.this); } else { channelsListDialog.setTitle(dialogtitle); } try { channelsListDialog.show(); } catch (IllegalStateException e) { //App lost focus already } ChannelListFragment channels = (ChannelListFragment) getSupportFragmentManager() .findFragmentById(R.id.channelListFragment); Bundle args = new Bundle(); args.putInt("cid", event.cid()); channels.setArguments(args); } }); break; case NetworkConnection.EVENT_USERINFO: runOnUiThread(new Runnable() { @Override public void run() { updateUsersListFragmentVisibility(); supportInvalidateOptionsMenu(); if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); } }); if (launchBid == -1 && server == null && conn != null && conn.getUserInfo() != null) launchBid = conn.getUserInfo().last_selected_bid; break; case NetworkConnection.EVENT_STATUSCHANGED: try { event = (IRCCloudJSONObject) obj; if (event != null && server != null && event.cid() == server.cid) { runOnUiThread(new Runnable() { @Override public void run() { supportInvalidateOptionsMenu(); } }); } } catch (Exception e1) { e1.printStackTrace(); } break; case NetworkConnection.EVENT_MAKESERVER: ServersDataSource.Server s = (ServersDataSource.Server) obj; if (server != null && s != null && s.cid == server.cid) { runOnUiThread(new Runnable() { @Override public void run() { supportInvalidateOptionsMenu(); update_subtitle(); } }); } else { cidToOpen = s.cid; bufferToOpen = "*"; } break; case NetworkConnection.EVENT_BUFFERARCHIVED: case NetworkConnection.EVENT_BUFFERUNARCHIVED: event_bid = (Integer) obj; if (buffer != null && event_bid == buffer.bid) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); } }); } if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); break; case NetworkConnection.EVENT_JOIN: event = (IRCCloudJSONObject) obj; if (event != null && buffer != null && event.bid() == buffer.bid && event.type().equals("you_joined_channel")) { runOnUiThread(new Runnable() { @Override public void run() { supportInvalidateOptionsMenu(); updateUsersListFragmentVisibility(); } }); } break; case NetworkConnection.EVENT_PART: case NetworkConnection.EVENT_KICK: event = (IRCCloudJSONObject) obj; if (event != null && buffer != null && event.bid() == buffer.bid && event.type().toLowerCase().startsWith("you_")) { runOnUiThread(new Runnable() { @Override public void run() { supportInvalidateOptionsMenu(); updateUsersListFragmentVisibility(); } }); } break; case NetworkConnection.EVENT_CHANNELINIT: ChannelsDataSource.Channel channel = (ChannelsDataSource.Channel) obj; if (channel != null && buffer != null && channel.bid == buffer.bid) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); supportInvalidateOptionsMenu(); updateUsersListFragmentVisibility(); } }); } break; case NetworkConnection.EVENT_BACKLOG_END: runOnUiThread(new Runnable() { @Override public void run() { errorMsg.setVisibility(View.GONE); error = null; if (progressBar.getVisibility() == View.VISIBLE) { if (Build.VERSION.SDK_INT >= 16) { progressBar.animate().alpha(0).setDuration(200).withEndAction(new Runnable() { @Override public void run() { progressBar.setVisibility(View.GONE); } }); } else { progressBar.setVisibility(View.GONE); } } getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowCustomEnabled(true); if (drawerLayout != null) { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); getSupportActionBar().setHomeButtonEnabled(true); updateUsersListFragmentVisibility(); } if (ServersDataSource.getInstance().count() < 1) { Crashlytics.log(Log.DEBUG, "IRCCloud", "No servers configured, launching add dialog"); addNetwork(); } else { if (server == null || launchURI != null || launchBid != -1) { Crashlytics.log(Log.DEBUG, "IRCCloud", "Backlog loaded and we're waiting for a buffer, switching now"); if (launchURI == null || !open_uri(launchURI)) { if (launchBid == -1 || !open_bid(launchBid)) { if (conn == null || conn.getUserInfo() == null || !open_bid(conn.getUserInfo().last_selected_bid)) { if (!open_bid(BuffersDataSource.getInstance().firstBid())) { if (drawerLayout != null && NetworkConnection.getInstance().ready && findViewById(R.id.usersListFragment2) == null) { drawerLayout.openDrawer(Gravity.LEFT); } } } } } } update_subtitle(); } if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); photoBtn.setEnabled(true); if (Build.VERSION.SDK_INT >= 11) photoBtn.setAlpha(1); } }); //TODO: prune and pop the back stack if the current BID has disappeared break; case NetworkConnection.EVENT_CONNECTIONDELETED: case NetworkConnection.EVENT_DELETEBUFFER: Integer id = (Integer) obj; if (what == NetworkConnection.EVENT_DELETEBUFFER) { synchronized (backStack) { for (int i = 0; i < backStack.size(); i++) { if (backStack.get(i).equals(id)) { backStack.remove(i); i--; } } } } if (buffer != null && id == ((what == NetworkConnection.EVENT_CONNECTIONDELETED) ? buffer.cid : buffer.bid)) { synchronized (backStack) { while (backStack != null && backStack.size() > 0) { final Integer bid = backStack.get(0); backStack.remove(0); b = BuffersDataSource.getInstance().getBuffer(bid); if (b != null) { runOnUiThread(new Runnable() { @Override public void run() { onBufferSelected(bid); if (backStack.size() > 0) backStack.remove(0); } }); return; } } } runOnUiThread(new Runnable() { @Override public void run() { if (BuffersDataSource.getInstance().count() == 0) { startActivity(new Intent(MainActivity.this, EditConnectionActivity.class)); finish(); } else { if ((NetworkConnection.getInstance().getUserInfo() == null || !open_bid(NetworkConnection.getInstance().getUserInfo().last_selected_bid)) && !open_bid(BuffersDataSource.getInstance().firstBid())) finish(); } } }); } runOnUiThread(new Runnable() { @Override public void run() { if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); } }); break; case NetworkConnection.EVENT_CHANNELMODE: case NetworkConnection.EVENT_CHANNELTOPIC: event = (IRCCloudJSONObject) obj; if (event != null && buffer != null && event.bid() == buffer.bid) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); } }); } break; case NetworkConnection.EVENT_SELFBACK: case NetworkConnection.EVENT_AWAY: try { event = (IRCCloudJSONObject) obj; if (event != null && buffer != null && event.cid() == buffer.cid && event.getString("nick").equalsIgnoreCase(buffer.name)) { runOnUiThread(new Runnable() { @Override public void run() { update_subtitle(); } }); } } catch (Exception e1) { e1.printStackTrace(); } break; case NetworkConnection.EVENT_HEARTBEATECHO: boolean shouldRefresh = false; event = (IRCCloudJSONObject) obj; JsonNode seenEids = event.getJsonNode("seenEids"); Iterator<Map.Entry<String, JsonNode>> iterator = seenEids.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); JsonNode eids = entry.getValue(); Iterator<Map.Entry<String, JsonNode>> j = eids.fields(); while (j.hasNext()) { Map.Entry<String, JsonNode> eidentry = j.next(); Integer bid = Integer.valueOf(eidentry.getKey()); if (buffer != null && bid != buffer.bid) { shouldRefresh = true; } } } if (shouldRefresh) { runOnUiThread(new Runnable() { @Override public void run() { if (refreshUpIndicatorTask != null) refreshUpIndicatorTask.cancel(true); refreshUpIndicatorTask = new RefreshUpIndicatorTask(); refreshUpIndicatorTask.execute((Void) null); } }); } break; case NetworkConnection.EVENT_FAILURE_MSG: event = (IRCCloudJSONObject) obj; if (event != null && event.has("_reqid")) { int reqid = event.getInt("_reqid"); if (pendingEvents.containsKey(reqid)) { EventsDataSource.Event e = pendingEvents.get(reqid); EventsDataSource.getInstance().deleteEvent(e.eid, e.bid); pendingEvents.remove(event.getInt("_reqid")); e.failed = true; e.bg_color = R.color.error; if (e.expiration_timer != null) e.expiration_timer.cancel(); conn.notifyHandlers(NetworkConnection.EVENT_BUFFERMSG, e); } } else { if (event.getString("message").equalsIgnoreCase("auth")) { conn.logout(); Intent i = new Intent(MainActivity.this, LoginActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); finish(); } if (event.getString("message").equalsIgnoreCase("set_shard")) { NetworkConnection.getInstance().disconnect(); NetworkConnection.getInstance().ready = false; SharedPreferences.Editor editor = getSharedPreferences("prefs", 0).edit(); editor.putString("session_key", event.getString("cookie")); if (event.has("websocket_host")) { NetworkConnection.IRCCLOUD_HOST = event.getString("websocket_host"); NetworkConnection.IRCCLOUD_PATH = event.getString("websocket_path"); } editor.putString("host", NetworkConnection.IRCCLOUD_HOST); editor.putString("path", NetworkConnection.IRCCLOUD_PATH); editor.commit(); NetworkConnection.getInstance().connect(event.getString("cookie")); } } try { error = event.getString("message"); if (error.equals("temp_unavailable")) error = "Your account is temporarily unavailable"; runOnUiThread(new Runnable() { @Override public void run() { updateReconnecting(); } }); } catch (Exception ex) { ex.printStackTrace(); } break; case NetworkConnection.EVENT_BUFFERMSG: try { EventsDataSource.Event e = (EventsDataSource.Event) obj; if (e != null && buffer != null) { if (e.bid != buffer.bid && upDrawable != null) { BuffersDataSource.Buffer buf = BuffersDataSource.getInstance().getBuffer(e.bid); if (e.isImportant(buf.type)) { if (upDrawable.getColor() != redColor && (e.highlight || buf.type.equals("conversation"))) { runOnUiThread(new Runnable() { @Override public void run() { upDrawable.setColor(redColor); } }); } else if (upDrawable.getColor() == greyColor) { JSONObject channelDisabledMap = null; JSONObject bufferDisabledMap = null; if (NetworkConnection.getInstance().getUserInfo() != null && NetworkConnection.getInstance().getUserInfo().prefs != null) { try { if (NetworkConnection.getInstance().getUserInfo().prefs .has("channel-disableTrackUnread")) channelDisabledMap = NetworkConnection.getInstance().getUserInfo().prefs .getJSONObject("channel-disableTrackUnread"); if (NetworkConnection.getInstance().getUserInfo().prefs .has("buffer-disableTrackUnread")) bufferDisabledMap = NetworkConnection.getInstance().getUserInfo().prefs .getJSONObject("buffer-disableTrackUnread"); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } if (buf.type.equalsIgnoreCase("channel") && channelDisabledMap != null && channelDisabledMap.has(String.valueOf(buf.bid)) && channelDisabledMap.getBoolean(String.valueOf(buf.bid))) break; else if (bufferDisabledMap != null && bufferDisabledMap.has(String.valueOf(buf.bid)) && bufferDisabledMap.getBoolean(String.valueOf(buf.bid))) break; runOnUiThread(new Runnable() { @Override public void run() { upDrawable.setColor(blueColor); } }); } } } if (e.from.equalsIgnoreCase(buffer.name)) { pendingEvents.clear(); } else if (pendingEvents.containsKey(e.reqid)) { pendingEvents.remove(e.reqid); } } } catch (Exception e1) { } break; } }
From source file:com.guardtrax.ui.screens.HomeScreen.java
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString("message", "Restoring GuardTrax"); outState.putString("darfileName", GTConstants.darfileName); outState.putString("tarfileName", GTConstants.tarfileName); outState.putString("trpfilename", GTConstants.trpfilename); outState.putString("srpfileName", GTConstants.srpfileName); outState.putString("currentState", Utility.getcurrentState()); outState.putString("getsessionStart", Utility.getsessionStart()); outState.putString("selectedCode", selectedCode); outState.putString("lunchTime", lunchTime); outState.putString("breakTime", breakTime); outState.putString("signaturefileName", signaturefileName); outState.putString("tourName", GTConstants.tourName); outState.putString("tourTime", tourTime); outState.putLong("tourEnd", tourEnd); outState.putInt("lunchoutLocation", lunchoutLocation); outState.putInt("breakoutLocation", breakoutLocation); outState.putInt("touritemNumber", touritemNumber); outState.putBoolean("chekUpdate", chekUpdate); outState.putBoolean("send_data", GTConstants.sendData); outState.putBoolean("isTour", GTConstants.isTour); outState.putBoolean("isGeoFence", GTConstants.isGeoFence); //Save data for main service String value = String.valueOf(GTConstants.sendData) + "," + GTConstants.darfileName + "," + GTConstants.tarfileName + "," + GTConstants.trpfilename + "," + GTConstants.srpfileName + "," + GTConstants.tourName;/*from w ww . ja va2 s .com*/ Utility.storesharedPreference(HomeScreen.this, "serviceString", value); // Save away the original text, so we still have it if the activity // needs to be killed while paused. //outState.putString("my_text", sMyText); //outState.putInt("my_int", nMyInt); //Toast.makeText(this, "onSaveInstanceState()", Toast.LENGTH_LONG).show(); }
From source file:android.app.Activity.java
/** * Migrate the application to other device. * This method is called by the Android system. * * @hide/*from w w w .j a va 2s.c om*/ * @param savedInstanceState A state the application needs to restore. * @return true if migration successed. */ private boolean systemMigrate(Bundle savedInstanceState) { boolean result = true; String cName; String pName; if (savedInstanceState == null) savedInstanceState = new Bundle(); /* store Intent object this Activity has and requestCode for next Activity */ savedInstanceState.putParcelable("MIGRATED_INTENT", getIntent()); savedInstanceState.putInt("MIGRATED REQUEST CODE", currentCode); savedInstanceState.putBundle("MIGRATED REQUEST OPTIONS", currentOption); currentCode = -1; currentOption = null; if (mMigrator == null) { mMigrator = IMigratorService.Stub.asInterface(ServiceManager.getService("Migrator")); } pName = getPackageName(); cName = mComponent.getClassName(); try { /* mStartedActivity is true if this Activity calls startActivityForResult(). * This means the next Activity exists. */ result = mMigrator.migrate(savedInstanceState, pName, cName, mStartedActivity); mStartedActivity = false; } catch (RemoteException e) { Log.w("MIGRATOR", "Migrate failed"); result = false; e.printStackTrace(); } return result; }