Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- public static final String ACTION_ADD_TO_QUEUE = "add_to_queue";
- public static final String ACTION_PLAY_SONG = "play_song";
- public static final String ACTION_REFRESH = "resfresh";
- public static final String ACTION_SET_AS_NEXT_TRACK = "set_as_next_track";
- public static final String ACTION_SHOW_ALBUM = "show_album";
- public static final String ACTION_SHOW_ARTIST = "show_artist";
- public static final String ALBUM_ARTIST = "artist";
- public static final String ALBUM_ID = "id";
- public static final String ALBUM_NAME = "name";
- public static final String ALBUM_TRACK_COUNT = "track_count";
- public static final String ALBUM_YEAR = "year";
- public static final String ARTIST_ALBUM_COUNT = "album_count";
- public static final String ARTIST_ARTIST_ID = "artist_id";
- public static final String ARTIST_ARTIST_NAME = "artist_name";
- public static final String ARTIST_TRACK_COUNT = "track_count";
- public static String KEY_NUMBER_UNLOCK_APPEAR = "KEY_SHOW_ADS_MP3_PLAYER)";
- private static final int REQUEST_WRITE_APP_DETAIL = 1234;
- private static final int SEARCH_ACTIVITY = 234;
- public static final String SONG_ALBUM = "song_album";
- public static final String SONG_ALBUM_ID = "song_album_id";
- public static final String SONG_ARTIST = "song_artist";
- private static final String SONG_DURATION = "song_duration";
- public static final String SONG_ID = "song_id";
- public static final String SONG_TITLE = "song_title";
- public static final String SONG_TRACK_NUMBER = "song_track_number";
- public static String dtStart = "2016-09-22T00:00:00Z";
- public static int showAfterCount = 0;
- private final int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124;
- private DrawerLayout mDrawerLayout;
- private Handler mHandler = new Handler();
- private HmsPickerDialogHandler mHmsPickerHandler = new HmsPickerDialogHandler() {
- public void onDialogHmsSet(int reference, int hours, int minutes, int seconds) {
- SleepTimer.setTimer(MainActivity.this, PreferenceManager.getDefaultSharedPreferences(MainActivity.this), ((hours * 3600) + (minutes * 60)) + seconds);
- }
- };
- private NavigationView mNavigationView;
- private Intent mOnActivityResultIntent;
- private OnClickListener mOnClickListener = new OnClickListener() {
- public void onClick(View v) {
- if (MainActivity.this.mPlaybackService != null) {
- switch (v.getId()) {
- case R.id.track_info:
- NavigationUtils.showPlaybackActivity(MainActivity.this);
- return;
- case R.id.quick_prev:
- case R.id.prev:
- MainActivity.this.mPlaybackService.playPrev(true);
- return;
- case R.id.quick_play_pause_toggle:
- case R.id.play_pause_toggle:
- MainActivity.this.mPlaybackService.toggle();
- return;
- case R.id.quick_next:
- case R.id.next:
- MainActivity.this.mPlaybackService.playNext(true);
- return;
- case R.id.action_equalizer:
- NavigationUtils.showEqualizer(MainActivity.this);
- return;
- default:
- return;
- }
- }
- }
- };
- private PlaybackRequests mPlaybackRequests;
- private PlaybackService mPlaybackService;
- private ProgressBar mProgressBar;
- private boolean mServiceBound = false;
- private ServiceConnection mServiceConnection = new ServiceConnection() {
- public void onServiceConnected(ComponentName name, IBinder service) {
- MainActivity.this.mPlaybackService = ((PlaybackBinder) service).getService();
- MainActivity.this.mServiceBound = true;
- MainActivity.this.mPlaybackRequests.sendRequests();
- MainActivity.this.updateAll();
- }
- public void onServiceDisconnected(ComponentName name) {
- MainActivity.this.mServiceBound = false;
- }
- };
- private Intent mServiceIntent;
- private BroadcastReceiver mServiceListener = new BroadcastReceiver() {
- public void onReceive(Context context, Intent intent) {
- if (MainActivity.this.mPlaybackService != null) {
- String action = intent.getAction();
- Log.d("action", action);
- if (action.equals(PlaybackService.PLAYSTATE_CHANGED)) {
- MainActivity.this.setButtonDrawable();
- if (MainActivity.this.mPlaybackService.isPlaying()) {
- MainActivity.this.mHandler.post(MainActivity.this.mUpdateProgressBar);
- } else {
- MainActivity.this.mHandler.removeCallbacks(MainActivity.this.mUpdateProgressBar);
- }
- } else if (action.equals(PlaybackService.META_CHANGED)) {
- MainActivity.this.updateTrackInfo();
- }
- }
- }
- };
- private DialogInterface.OnClickListener mSleepTimerDialogListener = new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- switch (which) {
- case -2:
- SleepTimer.cancelTimer(MainActivity.this, PreferenceManager.getDefaultSharedPreferences(MainActivity.this));
- return;
- case -1:
- DialogUtils.showSleepHmsPicker(MainActivity.this, MainActivity.this.mHmsPickerHandler);
- return;
- default:
- return;
- }
- }
- };
- private int mThumbSize;
- private Runnable mUpdateProgressBar = new Runnable() {
- public void run() {
- MainActivity.this.updateProgressBar();
- MainActivity.this.mHandler.postDelayed(MainActivity.this.mUpdateProgressBar, 1000);
- }
- };
- OnBackpressCallback onBackpressListener;
- public interface OnBackpressCallback {
- void onUserBackpress();
- }
- private class PlaybackRequests {
- private Song mAddToQueue;
- private boolean mAutoPlay;
- private int mIndex;
- private Song mNextTrack;
- private List<Song> mPlayList;
- private PlaybackRequests() {
- }
- PlaybackRequests(MainActivity mainActivity, PlaybackRequests playbackRequests) {
- this();
- }
- private void requestPlayList(List<Song> playList, int index, boolean autoPlay) {
- if (MainActivity.this.mPlaybackService != null) {
- MainActivity.this.mPlaybackService.setPlayList(playList, 0, true);
- return;
- }
- this.mPlayList = playList;
- this.mIndex = index;
- this.mAutoPlay = autoPlay;
- }
- public void requestAddToQueue(Song song) {
- if (MainActivity.this.mPlaybackService != null) {
- MainActivity.this.mPlaybackService.addToQueue(song);
- } else {
- this.mAddToQueue = song;
- }
- }
- public void requestAsNextTrack(Song song) {
- if (MainActivity.this.mPlaybackService != null) {
- MainActivity.this.mPlaybackService.setAsNextTrack(song);
- } else {
- this.mNextTrack = song;
- }
- }
- public void sendRequests() {
- if (MainActivity.this.mPlaybackService != null) {
- if (this.mPlayList != null) {
- MainActivity.this.mPlaybackService.setPlayList(this.mPlayList, this.mIndex, this.mAutoPlay);
- this.mPlayList = null;
- }
- if (this.mAddToQueue != null) {
- MainActivity.this.mPlaybackService.addToQueue(this.mAddToQueue);
- this.mAddToQueue = null;
- }
- if (this.mNextTrack != null) {
- MainActivity.this.mPlaybackService.setAsNextTrack(this.mNextTrack);
- this.mNextTrack = null;
- }
- }
- }
- }
- private void callAds() {
- }
- public DrawerLayout getDrawerLayout() {
- return this.mDrawerLayout;
- }
- protected void onCreate(Bundle savedInstanceState) {
- setTheme();
- super.onCreate(savedInstanceState);
- Log.d("getDensityName", ImageHelper.getDensityName(this));
- setVolumeControlStream(3);
- setContentView(R.layout.activity_main);
- PreScmTeam.startApp(this);
- ScpMasterAd.showAdsStartApp(this);
- BackgroundHelper.setViewBackground(this, findViewById(R.id.drawer_layout));
- StrictMode.setThreadPolicy(new Builder().permitAll().build());
- this.mPlaybackRequests = new PlaybackRequests(this, null);
- if (savedInstanceState == null) {
- showLibrary();
- }
- findViewById(R.id.quick_play_pause_toggle).setOnClickListener(this.mOnClickListener);
- findViewById(R.id.track_info).setOnClickListener(this.mOnClickListener);
- findViewById(R.id.quick_prev).setOnClickListener(this.mOnClickListener);
- findViewById(R.id.quick_next).setOnClickListener(this.mOnClickListener);
- this.mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
- this.mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
- this.mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
- this.mNavigationView.inflateHeaderView(R.layout.navigation_header);
- Bitmap bitmap = ImageHelper.blurRenderScript(this, ImageHelper.drawableToBitmap(this.mDrawerLayout.getBackground()), 25);
- ImageHelper.setBackgroundV16Plus(this, this.mDrawerLayout, bitmap);
- this.mNavigationView.setNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {
- public boolean onNavigationItemSelected(MenuItem menuItem) {
- MainActivity.this.mDrawerLayout.closeDrawers();
- switch (menuItem.getItemId()) {
- case R.id.action_equalizer:
- NavigationUtils.showEqualizer(MainActivity.this);
- break;
- case R.id.action_settings:
- NavigationUtils.showPreferencesActivity(MainActivity.this);
- break;
- case R.id.action_library:
- MainActivity.this.showLibrary();
- break;
- case R.id.action_favorites:
- MainActivity.this.showFavorites();
- break;
- case R.id.action_play_stream:
- if (MainActivity.this.mPlaybackService != null && MainActivity.this.mPlaybackService.isPlaying()) {
- MainActivity.this.mPlaybackService.pause("onNavigationItemSelected");
- }
- NavigationUtils.showPlayStreamActivity(MainActivity.this);
- break;
- case R.id.action_edit_file:
- if (MainActivity.this.mPlaybackService.isPlaying()) {
- MainActivity.this.mPlaybackService.pause("onNavigationItemSelected 2");
- }
- NavigationUtils.showEditFile(MainActivity.this);
- break;
- case R.id.action_feedback:
- MainActivity.this.openFeedback();
- break;
- case R.id.action_rate_us:
- MainActivity.this.openRateUs();
- break;
- case R.id.action_more_apps:
- MainActivity.this.openMoreApps();
- break;
- case R.id.action_share:
- MainActivity.this.openShare();
- break;
- case R.id.action_about:
- NavigationUtils.showAbout(MainActivity.this);
- break;
- }
- return true;
- }
- });
- if (VERSION.SDK_INT >= 23) {
- checkPermissionGranted();
- }
- try {
- AppSelfLib.showRateActivityNewStyleHighScore(this, 1, "songkaka@gmail.com", getPackageName());
- try {
- CoreService.initPackageName(this);
- } catch (Exception e) {
- e.printStackTrace();
- }
- callAds();
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- StorageUtils.creatFolderExtSDCard(this, Environment.getExternalStorageDirectory().toString());
- }
- private void setTheme() {
- setTheme(R.style.MainActivityDarkBlueGreyLight);
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- boolean dark = ThemeHelper.isDarkThemeSelected(this);
- switch (prefs.getInt(getString(R.string.pref_theme_key), 0)) {
- case 0:
- if (dark) {
- setTheme(R.style.MainActivityDarkBlueGreyDark);
- return;
- } else {
- setTheme(R.style.MainActivityDarkBlueGreyLight);
- return;
- }
- case 1:
- if (dark) {
- setTheme(R.style.MainActivityBlueGreyDark);
- return;
- } else {
- setTheme(R.style.MainActivityBlueGreyLight);
- return;
- }
- case 2:
- if (dark) {
- setTheme(R.style.MainActivityBlueDark);
- return;
- } else {
- setTheme(R.style.MainActivityBlueLight);
- return;
- }
- default:
- return;
- }
- }
- public void showLibrary() {
- this.mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
- this.mNavigationView.getMenu().findItem(R.id.action_library).setChecked(true);
- getSupportFragmentManager().beginTransaction().replace(R.id.container, LibraryFragment.newInstance()).commit();
- }
- public void showFavorites() {
- this.mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
- this.mNavigationView.getMenu().findItem(R.id.action_favorites).setChecked(true);
- getSupportFragmentManager().beginTransaction().replace(R.id.container, PlaylistFragment.newFavoritesFragment()).commit();
- }
- protected void onStop() {
- super.onStop();
- }
- protected void onPostResume() {
- super.onPostResume();
- if (this.mOnActivityResultIntent != null) {
- Bundle bundle = this.mOnActivityResultIntent.getExtras();
- if (this.mOnActivityResultIntent.getAction().equals("resfresh")) {
- refresh();
- } else if (this.mOnActivityResultIntent.getAction().equals("show_album")) {
- setFragment(AlbumFragment.newInstance(getAlbumFromBundle(bundle)));
- } else if (this.mOnActivityResultIntent.getAction().equals("show_artist")) {
- setFragment(ArtistFragment.newInstance(getArtistFromBundle(bundle)));
- } else {
- Song song = getSongFromBundle(bundle);
- if (this.mOnActivityResultIntent.getAction().equals("play_song")) {
- ArrayList<Song> songList = new ArrayList();
- songList.add(song);
- this.mPlaybackRequests.requestPlayList(songList, 0, true);
- } else if (this.mOnActivityResultIntent.getAction().equals("add_to_queue")) {
- this.mPlaybackRequests.requestAddToQueue(song);
- } else if (this.mOnActivityResultIntent.getAction().equals("set_as_next_track")) {
- this.mPlaybackRequests.requestAsNextTrack(song);
- }
- }
- this.mOnActivityResultIntent = null;
- }
- }
- public void refresh() {
- for (Fragment f : getSupportFragmentManager().getFragments()) {
- if (f != null) {
- Log.d("frag", f.getClass().getCanonicalName());
- ((BaseFragment) f).load();
- }
- }
- }
- private Album getAlbumFromBundle(Bundle bundle) {
- return new Album(bundle.getLong("id"), bundle.getString("name"), bundle.getString("artist"), bundle.getInt("year"), bundle.getInt("track_count"));
- }
- public void setFragment(Fragment f) {
- getSupportFragmentManager().beginTransaction().replace(R.id.container, f).addToBackStack(null).commit();
- }
- private Artist getArtistFromBundle(Bundle bundle) {
- return new Artist(bundle.getLong("artist_id"), bundle.getString("artist_name"), bundle.getInt("album_count"), bundle.getInt("track_count"));
- }
- private Song getSongFromBundle(Bundle bundle) {
- return new Song(bundle.getLong("song_id"), bundle.getString("song_title"), bundle.getString("song_artist"), bundle.getString("song_album"), bundle.getLong("song_album_id"), bundle.getInt("song_track_number"), bundle.getLong(SONG_DURATION));
- }
- protected void onDestroy() {
- super.onDestroy();
- }
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case 16908332:
- FragmentManager fm = getSupportFragmentManager();
- if (fm.getBackStackEntryCount() > 0) {
- fm.popBackStack();
- return true;
- }
- showLibrary();
- return true;
- case R.id.action_search:
- NavigationUtils.showSearchActivity(this, SEARCH_ACTIVITY);
- return true;
- case R.id.action_equalizer:
- NavigationUtils.showEqualizer(this);
- return true;
- case R.id.action_sleep_timer:
- if (!SleepTimer.isTimerSet(PreferenceManager.getDefaultSharedPreferences(this))) {
- DialogUtils.showSleepHmsPicker(this, this.mHmsPickerHandler);
- break;
- }
- DialogUtils.showSleepTimerDialog(this, this.mSleepTimerDialogListener);
- break;
- case R.id.action_preferences:
- NavigationUtils.showPreferencesActivity(this);
- break;
- case R.id.action_change_background:
- startActivity(new Intent(this, ChooseBackgroundActivity.class));
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- public void onSongSelected(List<Song> songList, int position) {
- if (this.mPlaybackService != null) {
- this.mPlaybackService.setPlayList(songList, position, true);
- }
- }
- public void onShuffleRequested(List<Song> songList, boolean play) {
- if (this.mPlaybackService != null) {
- this.mPlaybackService.setPlayListAndShuffle(songList, play);
- }
- }
- public void addToQueue(Song song) {
- if (this.mPlaybackService != null) {
- this.mPlaybackService.addToQueue(song);
- }
- }
- public void setAsNextTrack(Song song) {
- if (this.mPlaybackService != null) {
- this.mPlaybackService.setAsNextTrack(song);
- }
- }
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == SEARCH_ACTIVITY && resultCode == -1) {
- this.mOnActivityResultIntent = data;
- }
- if (requestCode == REQUEST_WRITE_APP_DETAIL) {
- reloadData();
- }
- }
- protected void onPause() {
- super.onPause();
- if (this.mServiceBound) {
- this.mPlaybackService = null;
- unregisterReceiver(this.mServiceListener);
- unbindService(this.mServiceConnection);
- this.mServiceBound = false;
- }
- this.mHandler.removeCallbacks(this.mUpdateProgressBar);
- }
- protected void onResume() {
- super.onResume();
- if (this.mServiceBound) {
- updateAll();
- return;
- }
- this.mServiceIntent = new Intent(this, PlaybackService.class);
- bindService(this.mServiceIntent, this.mServiceConnection, 1);
- startService(this.mServiceIntent);
- IntentFilter filter = new IntentFilter();
- filter.addAction(PlaybackService.META_CHANGED);
- filter.addAction(PlaybackService.PLAYSTATE_CHANGED);
- filter.addAction(PlaybackService.POSITION_CHANGED);
- filter.addAction(PlaybackService.ITEM_ADDED);
- filter.addAction(PlaybackService.ORDER_CHANGED);
- registerReceiver(this.mServiceListener, filter);
- }
- protected void onStart() {
- super.onStart();
- }
- private void updateAll() {
- if (this.mPlaybackService != null) {
- Log.d("playlist", "hasplaylist " + this.mPlaybackService.hasPlaylist());
- updateTrackInfo();
- setButtonDrawable();
- if (this.mPlaybackService.isPlaying()) {
- this.mHandler.post(this.mUpdateProgressBar);
- }
- }
- }
- private void updateTrackInfo() {
- View trackInfoLayout = findViewById(R.id.track_info);
- if (this.mPlaybackService == null || !this.mPlaybackService.hasPlaylist()) {
- trackInfoLayout.setVisibility(View.GONE);
- return;
- }
- if (trackInfoLayout.getVisibility() != View.VISIBLE) {
- trackInfoLayout.setVisibility(View.VISIBLE);
- trackInfoLayout.startAnimation(AnimationUtils.loadAnimation(this, R.anim.abc_grow_fade_in_from_bottom));
- }
- String title = this.mPlaybackService.getSongTitle();
- String artist = this.mPlaybackService.getArtistName();
- if (title != null) {
- ((TextView) findViewById(R.id.song_title)).setText(title);
- }
- if (artist != null) {
- ((TextView) findViewById(R.id.song_artist)).setText(artist);
- }
- long albumId = this.mPlaybackService.getAlbumId();
- ImageView minArtworkView = (ImageView) findViewById(R.id.artwork_min);
- Options dimensions = new Options();
- dimensions.inJustDecodeBounds = true;
- Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.default_song_thumb, dimensions);
- int width = dimensions.outWidth;
- this.mThumbSize = width;
- minArtworkView.getLayoutParams().width = width;
- minArtworkView.getLayoutParams().height = width;
- // ArtworkCache.getInstance().loadBitmap(Long.valueOf(albumId), minArtworkView, this.mThumbSize, this.mThumbSize, ArtworkHelper.getDefaultThumbDrawable(this));
- int duration = this.mPlaybackService.getTrackDuration();
- if (duration != -1) {
- this.mProgressBar.setMax(duration);
- updateProgressBar();
- }
- }
- private void setButtonDrawable() {
- if (this.mPlaybackService != null) {
- ImageButton quickButton = (ImageButton) findViewById(R.id.quick_play_pause_toggle);
- if (this.mPlaybackService.isPlaying()) {
- quickButton.setImageResource(R.drawable.btn_pause);
- } else {
- quickButton.setImageResource(R.drawable.btn_play);
- }
- }
- }
- private void updateProgressBar() {
- if (this.mPlaybackService != null) {
- this.mProgressBar.setProgress(this.mPlaybackService.getPlayerPosition());
- }
- }
- @SuppressLint({"NewApi"})
- public static boolean checkSystemWritePermission(final Context context) {
- boolean retVal = true;
- if (VERSION.SDK_INT >= 23) {
- retVal = System.canWrite(context);
- if (!retVal) {
- DialogUtils.showPermissionDialog(context, context.getString(R.string.permission_write_settings), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface arg0, int arg1) {
- MainActivity.openAndroidPermissionsMenu(context);
- }
- });
- }
- }
- return retVal;
- }
- public static void openAndroidPermissionsMenu(Context context) {
- Intent intent = new Intent("android.settings.action.MANAGE_WRITE_SETTINGS");
- intent.setData(Uri.parse("package:" + context.getPackageName()));
- context.startActivity(intent);
- }
- public void pauseMusic() {
- if (this.mPlaybackService.isPlaying()) {
- this.mPlaybackService.pause("pauseMusic");
- }
- }
- private void openFeedback() {
- AppSelfLib.sendMailFeedback(this, "songkaka@gmail.com", getPackageName());
- }
- private void openRateUs() {
- String appPackageName = getPackageName();
- try {
- startActivity(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + appPackageName)));
- } catch (ActivityNotFoundException e) {
- startActivity(new Intent("android.intent.action.VIEW", Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
- }
- }
- private void openMoreApps() {
- try {
- AppSelfLib.openGooglePlayNewApp(this);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private void openShare() {
- try {
- Intent sharingIntent = new Intent("android.intent.action.SEND");
- sharingIntent.setType("text/plain");
- String shareBody = getString(R.string.app_name) + " " + "https://play.google.com/store/apps/details?id=" + getPackageName();
- sharingIntent.putExtra("android.intent.extra.SUBJECT", getString(R.string.app_name));
- sharingIntent.putExtra("android.intent.extra.TEXT", shareBody);
- startActivity(Intent.createChooser(sharingIntent, "Share via"));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @SuppressLint({"NewApi"})
- private void checkPermissionGranted() {
- List<String> permissionsList = new ArrayList();
- if (checkSelfPermission("android.permission.READ_EXTERNAL_STORAGE") != 0) {
- permissionsList.add("android.permission.READ_EXTERNAL_STORAGE");
- }
- if (permissionsList.size() > 0) {
- requestPermissions((String[]) permissionsList.toArray(new String[permissionsList.size()]), 124);
- }
- }
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
- switch (requestCode) {
- case 124:
- Map<String, Integer> perms = new HashMap();
- perms.put("android.permission.READ_EXTERNAL_STORAGE", Integer.valueOf(0));
- for (int i = 0; i < permissions.length; i++) {
- perms.put(permissions[i], Integer.valueOf(grantResults[i]));
- }
- if (((Integer) perms.get("android.permission.READ_EXTERNAL_STORAGE")).intValue() == 0) {
- reloadData();
- return;
- } else if (!shouldShowRequestPermissionRationale("android.permission.READ_EXTERNAL_STORAGE")) {
- showDialogOpenSettings();
- return;
- } else {
- return;
- }
- default:
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- return;
- }
- }
- private void showDialogOpenSettings() {
- new AlertDialog.Builder(this).setMessage(getString(R.string.open_app_grant_permission)).setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface arg0, int arg1) {
- MainActivity.this.openAppDetailSettings();
- }
- }).setNegativeButton(getString(android.R.string.cancel), null).create().show();
- }
- private void openAppDetailSettings() {
- Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setData(Uri.fromParts("package", getPackageName(), null));
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
- intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
- startActivityForResult(intent, REQUEST_WRITE_APP_DETAIL);
- }
- public void onBackPressed() {
- Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.container);
- if (!(currentFragment instanceof LibraryFragment)) {
- super.onBackPressed();
- } else if (((LibraryFragment) currentFragment).getCurrentFragmentId() != LibraryFragment.FOLDER_TAB) {
- super.onBackPressed();
- } else if (this.onBackpressListener != null) {
- this.onBackpressListener.onUserBackpress();
- }
- }
- public void setOnBackpressListener(OnBackpressCallback listener) {
- this.onBackpressListener = listener;
- }
- private void reloadData() {
- try {
- Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.container);
- if (currentFragment instanceof LibraryFragment) {
- BaseFragment frag = (BaseFragment) ((LibraryFragment) currentFragment).getAdapter().getFragment(((LibraryFragment) currentFragment).getCurrentFragmentId());
- if (frag != null) {
- frag.load();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement