List of usage examples for android.support.v4.app FragmentManager findFragmentByTag
public abstract Fragment findFragmentByTag(String tag);
From source file:com.androzic.MapActivity.java
public boolean waypointTapped(Waypoint waypoint, int x, int y) { try {/*from www. jav a 2s .c o m*/ if (application.editingRoute != null) { routeSelected = -1; waypointSelected = application.getWaypointIndex(waypoint); wptQuickAction.show(map, x, y); return true; } else { Location loc = application.getLocationAsLocation(); FragmentManager fm = getSupportFragmentManager(); WaypointInfo waypointInfo = (WaypointInfo) fm.findFragmentByTag("waypoint_info"); if (waypointInfo == null) waypointInfo = new WaypointInfo(); waypointInfo.setWaypoint(waypoint); Bundle args = new Bundle(); args.putDouble("lat", loc.getLatitude()); args.putDouble("lon", loc.getLongitude()); waypointInfo.setArguments(args); waypointInfo.show(fm, "waypoint_info"); return true; } } catch (Exception e) { return false; } }
From source file:com.cnm.cnmrc.fragment.vodtvch.Base.java
@Override public void onDestroyView() { {/* w w w. j a va 2 s . c o m*/ // back key ? 2, ?, destoryview? ? count minus?. // ? TAG_FRAGMENT_BASE? fragment ? . . . // backstack? transaction? count ? minus ?. Fragment f = getActivity().getSupportFragmentManager() .findFragmentByTag(((MainActivity) getActivity()).TAG_FRAGMENT_BASE); if (f != null) { Log.i("hwang", "At Base TAG_FRAGMENT_BASE exist!!!"); } else { Log.i("hwang", "At Base TAG_FRAGMENT_BASE no exist!!!"); } f = getActivity().getSupportFragmentManager().findFragmentById(R.id.loading_data_panel); if (f != null) { Log.i("hwang", "At Base loading_data_panel exist!!!"); } else { Log.i("hwang", "At Base loading_data_panel no exist!!!"); } } // { // FragmentManager fm = getActivity().getSupportFragmentManager(); // Log.i("hwang", "before destory base view fragment count --> " + Integer.toString(fm.getBackStackEntryCount())); // Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag(((MainActivity) getActivity()).TAG_FRAGMENT_BASE); // if (f != null) { // getActivity().getSupportFragmentManager().beginTransaction().remove(f).commit(); // TAG_FRAGMENT_BASE? fragment ?? ?. // fm.executePendingTransactions(); // fragment ? ?. // } // Log.i("hwang", "after destory base view fragment count --> " + Integer.toString(fm.getBackStackEntryCount())); // // // check // // entry stack? ? 0 ? index?. // for (int entry = 0; entry < fm.getBackStackEntryCount(); entry++) { // Log.i("hwang", "Found fragment: " + fm.getBackStackEntryAt(entry).getId()); // } // } // { // // same above, ~ ?? ? TAG_FRAGMENT_BASE? ? fragment ? ?. // FragmentManager fm = getActivity().getSupportFragmentManager(); // Log.i("hwang", "before destory base view fragment count --> " + Integer.toString(fm.getBackStackEntryCount())); // Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag(((MainActivity) getActivity()).TAG_FRAGMENT_BASE); // if (f != null) { // fm.popBackStack(((MainActivity) getActivity()).TAG_FRAGMENT_BASE, 0); // ? ? null ?. // TAG_FRAGMENT_BASE? fragment ?. // fm.popBackStack(((MainActivity) getActivity()).TAG_FRAGMENT_BASE, FragmentManager.POP_BACK_STACK_INCLUSIVE); // TAG_FRAGMENT_BASE? fragment ?. ??..... // fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); // stack? fragment ?. // } // Log.i("hwang", "after destory base view fragment count --> " + Integer.toString(fm.getBackStackEntryCount())); // // // check // // entry stack? ? 0 ? index?. // for (int entry = 0; entry < fm.getBackStackEntryCount(); entry++) { // Log.i("hwang", "Found fragment: " + fm.getBackStackEntryAt(entry).getId()); // } // } // To clear stack you need to call: // // ScreenFragment.sDisableExitAnimation = true; // manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); // transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); // FragmentManager fm = getActivity().getSupportFragmentManager(); // for(int i = 0; i < fm.getBackStackEntryCount(); ++i) { // fm.popBackStack(); // } // But could equally have used something like: // // FragmentManager.popBackStack(String name, FragmentManager.POP_BACK_STACK_INCLUSIVE); // To go to top simply use: fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); // // transaction.replace(R.id.detailFragment, frag1); // Transaction.remove(null).add(frag1) // frag1 on view // // // transaction.replace(R.id.detailFragment, frag2).addToBackStack(null); // Transaction.remove(frag1).add(frag2).addToBackStack(null) // frag2 on view // // // transaction.replace(R.id.detailFragment, frag3); // Transaction.remove(frag2).add(frag3) // frag3 on view // FragmentManager fm = getActivity().getSupportFragmentManager(); // for(int i = 0; i < fm.getBackStackEntryCount(); ++i) { // fm.popBackStack(); // } // Use a name for your initial back stack state and use FragmentManager.popBackStack(String name, FragmentManager.POP_BACK_STACK_INCLUSIVE). // Use FragmentManager.getBackStackEntryCount()/getBackStackEntryAt().getId() to retrieve the ID of the first entry on the back stack, // and FragmentManager.popBackStack(int id, FragmentManager.POP_BACK_STACK_INCLUSIVE). // is supposed to pop the entire back stack... //FragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) // Base? onDestroyView() 2 . // ft.replace(R.id.loading_data_panel, base); // ft.add(R.id.loading_data_panel, base, ((MainActivity) getActivity()).TAG_FRAGMENT_BASE); // getBackStackEntryCount() ?? ... ? ? ? ??... // backstack? count ??? ? ?... FragmentManager fm = getActivity().getSupportFragmentManager(); if (!isFirstDepth) { // 1 depth?? ? depth?... //if(fm.getBackStackEntryCount() > 0 && fm.getBackStackEntryCount() < 8) { // indicator 8 ... Log.i("hwang", "before Base onDestroyView() fragment count --> " + Integer.toString(fm.getBackStackEntryCount())); Fragment f = getActivity().getSupportFragmentManager() .findFragmentByTag(((MainActivity) getActivity()).TAG_FRAGMENT_BASE); if (f != null) { // ?? ~~~~ // popBackStack()? ? ? ? ? ?. , backstack count ? minus? ??. //fm.popBackStack(((MainActivity) getActivity()).TAG_FRAGMENT_BASE, 0); // ? ? null ?. // TAG_FRAGMENT_BASE? fragment ?. //fm.popBackStack(((MainActivity) getActivity()).TAG_FRAGMENT_BASE, FragmentManager.POP_BACK_STACK_INCLUSIVE); // TAG_FRAGMENT_BASE? fragment ?. ??... //fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); // stack? fragment ?. //getActivity().getSupportFragmentManager().beginTransaction().remove(f).commit(); // TAG_FRAGMENT_BASE? fragment ?? ?. //fm.executePendingTransactions(); // fragment ? ?. // sidebar ? ... Fragment f1 = fm.findFragmentByTag(((MainActivity) getActivity()).TAG_FRAGMENT_VOD_TVCH); if (f1 != null) { if (((VodTvchMain) f1).mSlidingMenu.isOpening()) { getActivity().getSupportFragmentManager().beginTransaction().remove(f).commit(); //fm.getBackStackEntryAt(0); //fm.popBackStack(((MainActivity) getActivity()).TAG_FRAGMENT_BASE, FragmentManager.POP_BACK_STACK_INCLUSIVE); //fm.executePendingTransactions(); for (int i = 0; i < fm.getBackStackEntryCount(); i++) { // fm.popBackStack(((MainActivity) getActivity()).TAG_FRAGMENT_BASE, FragmentManager.POP_BACK_STACK_INCLUSIVE); fm.popBackStack(i, 0); // OK //fm.popBackStack(i, FragmentManager.POP_BACK_STACK_INCLUSIVE); // not OK } } } } Log.i("hwang", "after Base onDestroyView() fragment count --> " + Integer.toString(fm.getBackStackEntryCount())); // check // entry stack? ? 0 ? index?. for (int entry = 0; entry < fm.getBackStackEntryCount(); entry++) { Log.i("hwang", "At Base onDestroyView() Found fragment: " + fm.getBackStackEntryAt(entry).getId()); } deleteDepthLevel(); { f = getActivity().getSupportFragmentManager().findFragmentById(R.id.loading_data_panel); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); if (f != null) { if (f.isHidden()) ft.show(f).commit(); // loading_data_panel TAG_FRAGMENT_BASE ?. ? // f --> VodList{42626a88 #12 id=0x7f0c0048 base} // f --> VodList{42624ab0 #11 id=0x7f0c0048 base} // f --> VodList{42622ad8 #10 id=0x7f0c0048 base} // f --> VodList{42620b00 #9 id=0x7f0c0048 base} // f --> VodList{4261ea88 #8 id=0x7f0c0048 base} // f --> VodList{4261c560 #7 id=0x7f0c0048} } } } super.onDestroyView(); }
From source file:com.filemanager.free.fragments.Main.java
public void goBack() { if (openMode == 2) { loadlist(home, false, 0);/*ww w .j ava2s . c o m*/ return; } File f = new File(CURRENT_PATH); if (!results && !mRetainSearchTask) { if (selection) { adapter.toggleChecked(false); } else { if (openMode == 1) try { if (!smbPath.equals(CURRENT_PATH)) { String path = (new SmbFile(CURRENT_PATH).getParent()); loadlist((path), true, openMode); } else loadlist(home, false, 0); } catch (MalformedURLException e) { e.printStackTrace(); } else if (CURRENT_PATH.equals("/") || CURRENT_PATH.equals(home)) MAIN_ACTIVITY.exit(); else if (utils.canGoBack(f)) { loadlist(f.getParent(), true, openMode); } else MAIN_ACTIVITY.exit(); } } else if (!results && mRetainSearchTask) { // case when we had pressed on an item from search results and wanna go back // leads to resuming the search task if (MainActivityHelper.SEARCH_TEXT != null) { // starting the search query again :O MAIN_ACTIVITY.mainFragment = (Main) MAIN_ACTIVITY.getFragment().getTab(); FragmentManager fm = MAIN_ACTIVITY.getSupportFragmentManager(); // getting parent path to resume search from there String parentPath = new File(CURRENT_PATH).getParent(); // don't fuckin' remove this line, we need to change // the path back to parent on back press CURRENT_PATH = parentPath; MainActivityHelper.addSearchFragment(fm, new SearchAsyncHelper(), parentPath, MainActivityHelper.SEARCH_TEXT, openMode, ROOT_MODE); } else loadlist(CURRENT_PATH, true, -1); mRetainSearchTask = false; } else { // to go back after search list have been popped FragmentManager fm = getActivity().getSupportFragmentManager(); SearchAsyncHelper fragment = (SearchAsyncHelper) fm.findFragmentByTag(MainActivity.TAG_ASYNC_HELPER); if (fragment != null) { if (fragment.mSearchTask.getStatus() == AsyncTask.Status.RUNNING) { fragment.mSearchTask.cancel(true); } } loadlist(new File(CURRENT_PATH).getPath(), true, -1); results = false; } }
From source file:com.httrack.android.HTTrackActivity.java
/** * Start the runner/*from w w w. j a v a2 s . c o m*/ */ protected synchronized void startRunner() { // First attempt to reclaim a running one (orientation change) if (runner == null) { final FragmentManager fm = getSupportFragmentManager(); runner = (RunnerFragment) fm.findFragmentByTag(sessionID); // onAttach() should be called. } // Then, create one if necessary if (runner == null) { final FragmentManager fm = getSupportFragmentManager(); runner = new RunnerFragment(); runner.setParent(this); fm.beginTransaction().add(runner, sessionID).commit(); } }
From source file:com.igniva.filemanager.fragments.Main.java
public void goBack() { if (openMode == 2) { loadlist(home, false, 0);//from w w w .ja va2s . c o m return; } File f = new File(CURRENT_PATH); if (!results && !mRetainSearchTask) { // normal case if (selection) { adapter.toggleChecked(false); } else { if (openMode == 1) try { if (!smbPath.equals(CURRENT_PATH)) { String path = (new SmbFile(CURRENT_PATH).getParent()); loadlist((path), true, openMode); } else loadlist(home, false, 0); } catch (MalformedURLException e) { e.printStackTrace(); } else if (CURRENT_PATH.equals("/") || CURRENT_PATH.equals(home)) { // Toast.makeText(getActivity(), "finish...", Toast.LENGTH_SHORT).show(); if (MAIN_ACTIVITY.backPressedToExitOnce) { showInterstitial(); } MAIN_ACTIVITY.exit(); } else if (utils.canGoBack(f)) { loadlist(f.getParent(), true, openMode); } else { Toast.makeText(getActivity(), "finish...", Toast.LENGTH_SHORT).show(); showInterstitial(); MAIN_ACTIVITY.exit(); } } } else if (!results && mRetainSearchTask) { // case when we had pressed on an item from search results and wanna go back // leads to resuming the search task if (MainActivityHelper.SEARCH_TEXT != null) { // starting the search query again :O MAIN_ACTIVITY.mainFragment = (Main) MAIN_ACTIVITY.getFragment().getTab(); FragmentManager fm = MAIN_ACTIVITY.getSupportFragmentManager(); // getting parent path to resume search from there String parentPath = new File(CURRENT_PATH).getParent(); // don't fuckin' remove this line, we need to change // the path back to parent on back press CURRENT_PATH = parentPath; MainActivityHelper.addSearchFragment(fm, new SearchAsyncHelper(), parentPath, MainActivityHelper.SEARCH_TEXT, openMode, BaseActivity.rootMode, Sp.getBoolean(SearchAsyncHelper.KEY_REGEX, false), Sp.getBoolean(SearchAsyncHelper.KEY_REGEX_MATCHES, false)); } else loadlist(CURRENT_PATH, true, -1); mRetainSearchTask = false; } else { // to go back after search list have been popped FragmentManager fm = getActivity().getSupportFragmentManager(); SearchAsyncHelper fragment = (SearchAsyncHelper) fm.findFragmentByTag(MainActivity.TAG_ASYNC_HELPER); if (fragment != null) { if (fragment.mSearchTask.getStatus() == AsyncTask.Status.RUNNING) { fragment.mSearchTask.cancel(true); } } loadlist(new File(CURRENT_PATH).getPath(), true, -1); results = false; } }
From source file:com.amaze.filemanager.fragments.MainFragment.java
public void goBack() { if (openMode == OpenMode.CUSTOM) { loadlist(home, false, OpenMode.FILE); return;/*w w w .j a v a 2s . com*/ } HybridFile currentFile = new HybridFile(openMode, CURRENT_PATH); if (!results) { if (!mRetainSearchTask) { // normal case if (selection) { adapter.toggleChecked(false); } else { if (openMode == OpenMode.SMB) { try { if (!smbPath.equals(CURRENT_PATH)) { String path = (new SmbFile(CURRENT_PATH).getParent()); loadlist((path), true, openMode); } else loadlist(home, false, OpenMode.FILE); } catch (MalformedURLException e) { e.printStackTrace(); } } else if (openMode == OpenMode.SFTP) { if (!CURRENT_PATH.substring("ssh://".length()).contains("/")) loadlist(home, false, OpenMode.FILE); else loadlist(currentFile.getParent(getContext()), true, openMode); } else if (CURRENT_PATH.equals("/") || CURRENT_PATH.equals(home) || CURRENT_PATH.equals(OTGUtil.PREFIX_OTG + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_BOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_DROPBOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/")) getMainActivity().exit(); else if (FileUtils.canGoBack(getContext(), currentFile)) { loadlist(currentFile.getParent(getContext()), true, openMode); } else getMainActivity().exit(); } } else { // case when we had pressed on an item from search results and wanna go back // leads to resuming the search task if (MainActivityHelper.SEARCH_TEXT != null) { // starting the search query again :O getMainActivity().mainFragment = (MainFragment) getMainActivity().getTabFragment() .getCurrentTabFragment(); FragmentManager fm = getMainActivity().getSupportFragmentManager(); // getting parent path to resume search from there String parentPath = new HybridFile(openMode, CURRENT_PATH).getParent(getActivity()); // don't fuckin' remove this line, we need to change // the path back to parent on back press CURRENT_PATH = parentPath; MainActivityHelper.addSearchFragment(fm, new SearchWorkerFragment(), parentPath, MainActivityHelper.SEARCH_TEXT, openMode, getMainActivity().isRootExplorer(), sharedPref.getBoolean(SearchWorkerFragment.KEY_REGEX, false), sharedPref.getBoolean(SearchWorkerFragment.KEY_REGEX_MATCHES, false)); } else loadlist(CURRENT_PATH, true, OpenMode.UNKNOWN); mRetainSearchTask = false; } } else { // to go back after search list have been popped FragmentManager fm = getActivity().getSupportFragmentManager(); SearchWorkerFragment fragment = (SearchWorkerFragment) fm .findFragmentByTag(MainActivity.TAG_ASYNC_HELPER); if (fragment != null) { if (fragment.mSearchAsyncTask.getStatus() == AsyncTask.Status.RUNNING) { fragment.mSearchAsyncTask.cancel(true); } } loadlist(new File(CURRENT_PATH).getPath(), true, OpenMode.UNKNOWN); results = false; } }
From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java
public void goBack() { if (openMode == OpenMode.CUSTOM) { loadlist(home, false, OpenMode.FILE); return;//from ww w. j a v a2 s. c o m } HFile currentFile = new HFile(openMode, CURRENT_PATH); if (!results) { if (!mRetainSearchTask) { // normal case if (selection) { adapter.toggleChecked(false); } else { if (openMode == OpenMode.SMB) { try { if (!smbPath.equals(CURRENT_PATH)) { String path = (new SmbFile(CURRENT_PATH).getParent()); loadlist((path), true, openMode); } else loadlist(home, false, OpenMode.FILE); } catch (MalformedURLException e) { e.printStackTrace(); } } else if (CURRENT_PATH.equals("/") || CURRENT_PATH.equals(home) || CURRENT_PATH.equals(OTGUtil.PREFIX_OTG + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_BOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_DROPBOX + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/") || CURRENT_PATH.equals(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/")) MAIN_ACTIVITY.exit(); else if (utils.canGoBack(getContext(), currentFile)) { loadlist(currentFile.getParent(getContext()), true, openMode); } else MAIN_ACTIVITY.exit(); } } else { // case when we had pressed on an item from search results and wanna go back // leads to resuming the search task if (MainActivityHelper.SEARCH_TEXT != null) { // starting the search query again :O MAIN_ACTIVITY.mainFragment = (MainFragment) MAIN_ACTIVITY.getFragment().getTab(); FragmentManager fm = MAIN_ACTIVITY.getSupportFragmentManager(); // getting parent path to resume search from there String parentPath = new HFile(openMode, CURRENT_PATH).getParent(getActivity()); // don't fuckin' remove this line, we need to change // the path back to parent on back press CURRENT_PATH = parentPath; MainActivityHelper.addSearchFragment(fm, new SearchAsyncHelper(), parentPath, MainActivityHelper.SEARCH_TEXT, openMode, BaseActivity.rootMode, sharedPref.getBoolean(SearchAsyncHelper.KEY_REGEX, false), sharedPref.getBoolean(SearchAsyncHelper.KEY_REGEX_MATCHES, false)); } else loadlist(CURRENT_PATH, true, OpenMode.UNKNOWN); mRetainSearchTask = false; } } else { // to go back after search list have been popped FragmentManager fm = getActivity().getSupportFragmentManager(); SearchAsyncHelper fragment = (SearchAsyncHelper) fm.findFragmentByTag(MainActivity.TAG_ASYNC_HELPER); if (fragment != null) { if (fragment.mSearchTask.getStatus() == AsyncTask.Status.RUNNING) { fragment.mSearchTask.cancel(true); } } loadlist(new File(CURRENT_PATH).getPath(), true, OpenMode.UNKNOWN); results = false; } }
From source file:com.amaze.filemanager.activities.MainActivity.java
/** * Called when the activity is first created. *///from w w w .j av a2s. c o m @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Sp = PreferenceManager.getDefaultSharedPreferences(this); initialisePreferences(); setTheme(); setContentView(R.layout.main_toolbar); initialiseViews(); DataUtils.clear(); DataUtils.registerOnDataChangedListener(this); tabHandler = new TabHandler(this, null, null, 1); utils = new Futils(); //requesting storage permissions if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) if (!checkStoragePermission()) requestStoragePermission(); mainActivityHelper = new MainActivityHelper(this); initialiseFab(); if (mAsyncHelperFragment != null) { FragmentManager fm = getSupportFragmentManager(); mAsyncHelperFragment = (AsyncHelper) fm.findFragmentByTag(TAG_ASYNC_HELPER); } history = new HistoryManager(this, "Table2"); history.initializeTable(DataUtils.HISTORY, 0); history.initializeTable(DataUtils.HIDDEN, 0); grid = new HistoryManager(this, "listgridmodes"); grid.initializeTable(DataUtils.LIST, 0); grid.initializeTable(DataUtils.GRID, 0); grid.initializeTable(DataUtils.BOOKS, 1); grid.initializeTable(DataUtils.DRIVE, 1); grid.initializeTable(DataUtils.SMB, 1); if (!Sp.getBoolean("booksadded", false)) { grid.make(DataUtils.BOOKS); Sp.edit().putBoolean("booksadded", true).commit(); } DataUtils.setHiddenfiles(history.readTable(DataUtils.HIDDEN)); DataUtils.setGridfiles(grid.readTable(DataUtils.GRID)); DataUtils.setListfiles(grid.readTable(DataUtils.LIST)); // initialize g+ api client as per preferences if (Sp.getBoolean("plus_pic", false)) { mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_LOGIN).build(); } util = new IconUtils(Sp, this); icons = new IconUtils(Sp, this); timer = new CountDownTimer(5000, 1000) { @Override public void onTick(long l) { } @Override public void onFinish() { crossfadeInverse(); } }; path = getIntent().getStringExtra("path"); openprocesses = getIntent().getBooleanExtra("openprocesses", false); try { intent = getIntent(); if (intent.getStringArrayListExtra("failedOps") != null) { ArrayList<BaseFile> failedOps = intent.getParcelableArrayListExtra("failedOps"); if (failedOps != null) { mainActivityHelper.showFailedOperationDialog(failedOps, intent.getBooleanExtra("move", false), this); } } if (intent.getAction() != null) if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) { // file picker intent mReturnIntent = true; Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show(); } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) { // ringtone picker intent mReturnIntent = true; mRingtonePickerIntent = true; Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show(); } else if (intent.getAction().equals(Intent.ACTION_VIEW)) { // zip viewer intent Uri uri = intent.getData(); openzip = true; zippath = uri.toString(); } } catch (Exception e) { } updateDrawer(); if (savedInstanceState == null) { if (openprocesses) { android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager() .beginTransaction(); transaction.replace(R.id.content_frame, new ProcessViewer()); // transaction.addToBackStack(null); select = 102; openprocesses = false; //title.setText(utils.getString(con, R.string.process_viewer)); //Commit the transaction transaction.commit(); supportInvalidateOptionsMenu(); } else { if (path != null && path.length() > 0) { HFile file = new HFile(HFile.UNKNOWN, path); file.generateMode(this); if (file.isDirectory()) goToMain(path); else { goToMain(""); utils.openFile(new File(path), this); } } else { goToMain(""); } } } else { COPY_PATH = savedInstanceState.getParcelableArrayList("COPY_PATH"); MOVE_PATH = savedInstanceState.getParcelableArrayList("MOVE_PATH"); oppathe = savedInstanceState.getString("oppathe"); oppathe1 = savedInstanceState.getString("oppathe1"); oparrayList = savedInstanceState.getParcelableArrayList("oparrayList"); operation = savedInstanceState.getInt("operation"); select = savedInstanceState.getInt("selectitem", 0); adapter.toggleChecked(select); //mainFragment = (Main) savedInstanceState.getParcelable("main_fragment"); } if (theme1 == 1) { mDrawerList.setBackgroundColor(ContextCompat.getColor(this, R.color.holo_dark_background)); } mDrawerList.setDivider(null); if (!isDrawerLocked) { mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer_l, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { mainActivity.onDrawerClosed(); } public void onDrawerOpened(View drawerView) { //title.setText("Amaze File Manager"); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_drawer_l); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mDrawerToggle.syncState(); } /*((ImageButton) findViewById(R.id.drawer_buttton)).setOnClickListener(new ImageView.OnClickListener() { @Override public void onClick(View view) { if (mDrawerLayout.isDrawerOpen(mDrawerLinear)) { mDrawerLayout.closeDrawer(mDrawerLinear); } else mDrawerLayout.openDrawer(mDrawerLinear); } });*/ if (mDrawerToggle != null) { mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_drawer_l); } //recents header color implementation if (Build.VERSION.SDK_INT >= 21) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Amaze", ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap(), Color.parseColor(skin)); ((Activity) this).setTaskDescription(taskDescription); } }
From source file:com.battlelancer.seriesguide.ui.dialogs.TraktCredentialsDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().setTitle(R.string.pref_trakt); final Context context = getActivity().getApplicationContext(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final View layout = inflater.inflate(R.layout.trakt_credentials_dialog, null); final FragmentManager fm = getFragmentManager(); final Bundle args = getArguments(); // restore the username from settings final String username = prefs.getString(SeriesGuidePreferences.KEY_TRAKTUSER, ""); // new account toggle final View mailviews = layout.findViewById(R.id.mailviews); mailviews.setVisibility(View.GONE); CheckBox newAccCheckBox = (CheckBox) layout.findViewById(R.id.checkNewAccount); newAccCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { mailviews.setVisibility(View.VISIBLE); } else { mailviews.setVisibility(View.GONE); }//from ww w .ja v a 2 s . c om } }); // status strip final TextView status = (TextView) layout.findViewById(R.id.status); final View progressbar = layout.findViewById(R.id.progressbar); final View progress = layout.findViewById(R.id.progress); progress.setVisibility(View.GONE); final Button connectbtn = (Button) layout.findViewById(R.id.connectbutton); final Button disconnectbtn = (Button) layout.findViewById(R.id.disconnectbutton); // enable buttons based on if there are saved credentials if (TextUtils.isEmpty(username)) { // user has to enable first disconnectbtn.setEnabled(false); } else { // make it obvious trakt is connected connectbtn.setEnabled(false); EditText usernameField = (EditText) layout.findViewById(R.id.username); usernameField.setEnabled(false); usernameField.setText(username); EditText passwordField = (EditText) layout.findViewById(R.id.password); passwordField.setEnabled(false); passwordField.setText("********"); // fake password newAccCheckBox.setEnabled(false); } connectbtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // prevent multiple instances connectbtn.setEnabled(false); disconnectbtn.setEnabled(false); // prevent user canceling the dialog setCancelable(false); final String username = ((EditText) layout.findViewById(R.id.username)).getText().toString(); final String passwordHash = Utils .toSHA1(((EditText) layout.findViewById(R.id.password)).getText().toString().getBytes()); final String email = ((EditText) layout.findViewById(R.id.email)).getText().toString(); final boolean isNewAccount = ((CheckBox) layout.findViewById(R.id.checkNewAccount)).isChecked(); final String traktApiKey = getResources().getString(R.string.trakt_apikey); AsyncTask<String, Void, Response> accountValidatorTask = new AsyncTask<String, Void, Response>() { @Override protected void onPreExecute() { progress.setVisibility(View.VISIBLE); progressbar.setVisibility(View.VISIBLE); status.setText(R.string.waitplease); } @Override protected Response doInBackground(String... params) { // check if we have any usable data if (username.length() == 0 || passwordHash == null) { return null; } // check for connectivity if (!AndroidUtils.isNetworkConnected(context)) { Response r = new Response(); r.status = TraktStatus.FAILURE; r.error = context.getString(R.string.offline); return r; } // use a separate ServiceManager here to avoid // setting wrong credentials final ServiceManager manager = new ServiceManager(); manager.setApiKey(traktApiKey); manager.setAuthentication(username, passwordHash); manager.setUseSsl(true); Response response = null; try { if (isNewAccount) { // create new account response = manager.accountService().create(username, passwordHash, email).fire(); } else { // validate existing account response = manager.accountService().test().fire(); } } catch (TraktException te) { response = te.getResponse(); } catch (ApiException ae) { response = null; } return response; } @Override protected void onPostExecute(Response response) { progressbar.setVisibility(View.GONE); connectbtn.setEnabled(true); setCancelable(true); if (response == null) { status.setText(R.string.trakt_generalerror); return; } if (response.status.equals(TraktStatus.FAILURE)) { status.setText(response.error); return; } // try to encrypt the password before storing it String passwordEncr = SimpleCrypto.encrypt(passwordHash, context); if (passwordEncr == null) { // password encryption failed status.setText(R.string.trakt_generalerror); return; } // prepare writing credentials to settings Editor editor = prefs.edit(); editor.putString(SeriesGuidePreferences.KEY_TRAKTUSER, username) .putString(SeriesGuidePreferences.KEY_TRAKTPWD, passwordEncr); if (response.status.equals(TraktStatus.SUCCESS) && passwordEncr.length() != 0 && editor.commit()) { // try setting new auth data for service manager if (Utils.getServiceManagerWithAuth(context, true) == null) { status.setText(R.string.trakt_generalerror); return; } // all went through dismiss(); if (isForwardingGivenTask) { if (TraktAction.values()[args .getInt(ShareItems.TRAKTACTION)] == TraktAction.CHECKIN_EPISODE) { FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag("progress-dialog"); if (prev != null) { ft.remove(prev); } ProgressDialog newFragment = ProgressDialog.newInstance(); newFragment.show(ft, "progress-dialog"); } // relaunch the trakt task which called us AndroidUtils.executeAsyncTask(new TraktTask(context, fm, args, null), new Void[] { null }); } } } }; accountValidatorTask.execute(); } }); disconnectbtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // clear trakt credentials new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { clearTraktCredentials(prefs); // force removing credentials from memory ServiceManager manager = Utils.getServiceManagerWithAuth(context, false); if (manager != null) { manager.setAuthentication(null, null); } return null; } }.execute(); dismiss(); } }); return layout; }