Example usage for android.app ProgressDialog setCancelable

List of usage examples for android.app ProgressDialog setCancelable

Introduction

In this page you can find the example usage for android.app ProgressDialog setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:org.alfresco.mobile.android.application.fragments.operations.OperationWaitingDialogFragment.java

public Dialog onCreateDialog(final Bundle savedInstanceState) {
    setRetainInstance(true);/*w  w  w  .  j a  va2  s.  co  m*/
    if (getArguments() != null) {
        operationType = getArguments().getInt(PARAM_TYPEID);
        intentId = getArguments().getString(PARAM_INTENTID);
        iconId = getArguments().getInt(PARAM_ICONID);
        title = getArguments().getString(PARAM_TITLEID);
        message = getArguments().getString(PARAM_MESSAGEID);
        parent = getArguments().getParcelable(PARAM_NODEID);
        nbItems = getArguments().getInt(PARAM_SIZE);
    }

    ProgressDialog dialog = new ProgressDialog(getActivity());
    if (iconId == 0) {
        iconId = R.drawable.ic_alfresco_logo;
    }
    dialog.setIcon(iconId);
    dialog.setTitle(title);
    if (message == null) {
        message = getString(R.string.waiting_operations);
    }
    dialog.setMessage(message);
    boolean indeterminate = true;
    if (nbItems > 0) {
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgress(0);
        dialog.setMax(nbItems);
        indeterminate = false;
    } else {
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    }
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    getActivity().getLoaderManager().restartLoader(this.hashCode(), null, this);

    return dialog;
}

From source file:com.synox.android.ui.dialog.IndeterminateProgressDialog.java

/**
 * {@inheritDoc}/*w w  w  . java2  s  . c om*/
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    /// create indeterminate progress dialog
    final ProgressDialog progressDialog = new ProgressDialog(getActivity(), R.style.ProgressDialogTheme);
    progressDialog.setIndeterminate(true);
    progressDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            ProgressBar v = (ProgressBar) progressDialog.findViewById(android.R.id.progress);
            v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.accent),
                    android.graphics.PorterDuff.Mode.MULTIPLY);

        }
    });

    /// set message
    int messageId = getArguments().getInt(ARG_MESSAGE_ID, R.string.placeholder_sentence);
    progressDialog.setMessage(getString(messageId));

    /// set cancellation behavior
    boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE, false);
    if (!cancelable) {
        progressDialog.setCancelable(false);
        // disable the back button
        OnKeyListener keyListener = new OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

                return keyCode == KeyEvent.KEYCODE_BACK;
            }

        };
        progressDialog.setOnKeyListener(keyListener);
    }

    return progressDialog;
}

From source file:org.telegram.ui.SessionsActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("SessionsTitle", R.string.SessionsTitle));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//from w w w. ja  v  a  2  s .  co m
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    listAdapter = new ListAdapter(context);

    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));

    emptyLayout = new LinearLayout(context);
    emptyLayout.setOrientation(LinearLayout.VERTICAL);
    emptyLayout.setGravity(Gravity.CENTER);
    //emptyLayout.setBackgroundResource(R.drawable.greydivider_bottom);
    emptyLayout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
            AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight()));

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.devices);
    emptyLayout.addView(imageView);
    LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    imageView.setLayoutParams(layoutParams2);

    TextView textView = new TextView(context);
    textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setText(LocaleController.getString("NoOtherSessions", R.string.NoOtherSessions));
    emptyLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.topMargin = AndroidUtilities.dp(16);
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER;
    textView.setLayoutParams(layoutParams2);

    textView = new TextView(context);
    textView.setTextColor(ContextCompat.getColor(context, R.color.disabled_text) /*0xff8a8a8a*/);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
    textView.setText(LocaleController.getString("NoOtherSessionsInfo", R.string.NoOtherSessionsInfo));
    emptyLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.topMargin = AndroidUtilities.dp(14);
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER;
    textView.setLayoutParams(layoutParams2);

    FrameLayout progressView = new FrameLayout(context);
    frameLayout.addView(progressView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    progressView.setLayoutParams(layoutParams);
    progressView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    ProgressBar progressBar = new ProgressBar(context);
    progressView.addView(progressBar);
    layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.WRAP_CONTENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.gravity = Gravity.CENTER;
    progressView.setLayoutParams(layoutParams);

    ListView listView = new ListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDrawSelectorOnTop(true);
    listView.setEmptyView(progressView);
    frameLayout.addView(listView);
    layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP;
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if (i == terminateAllSessionsRow) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(
                        LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions));
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations();
                                ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                                    @Override
                                    public void run(final TLObject response, final TLRPC.TL_error error) {
                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                if (getParentActivity() == null) {
                                                    return;
                                                }
                                                if (error == null && response instanceof TLRPC.TL_boolTrue) {
                                                    Toast toast = Toast.makeText(getParentActivity(),
                                                            LocaleController.getString("TerminateAllSessions",
                                                                    R.string.TerminateAllSessions),
                                                            Toast.LENGTH_SHORT);
                                                    toast.show();
                                                } else {
                                                    Toast toast = Toast
                                                            .makeText(getParentActivity(),
                                                                    LocaleController.getString("UnknownError",
                                                                            R.string.UnknownError),
                                                                    Toast.LENGTH_SHORT);
                                                    toast.show();
                                                }
                                                finishFragment();
                                            }
                                        });
                                        UserConfig.registeredForPush = false;
                                        UserConfig.saveConfig(false);
                                        MessagesController.getInstance().registerForPush(UserConfig.pushString);
                                        ConnectionsManager.getInstance()
                                                .setUserId(UserConfig.getClientUserId());
                                    }
                                });
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (i >= otherSessionsStartRow && i < otherSessionsEndRow) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.getString("TerminateSessionQuestion",
                        R.string.TerminateSessionQuestion));
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int option) {
                                final ProgressDialog progressDialog = new ProgressDialog(getParentActivity());
                                progressDialog
                                        .setMessage(LocaleController.getString("Loading", R.string.Loading));
                                progressDialog.setCanceledOnTouchOutside(false);
                                progressDialog.setCancelable(false);
                                progressDialog.show();

                                final TLRPC.TL_authorization authorization = sessions
                                        .get(i - otherSessionsStartRow);
                                TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization();
                                req.hash = authorization.hash;
                                ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                                    @Override
                                    public void run(final TLObject response, final TLRPC.TL_error error) {
                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                try {
                                                    progressDialog.dismiss();
                                                } catch (Exception e) {
                                                    FileLog.e("tmessages", e);
                                                }
                                                if (error == null) {
                                                    sessions.remove(authorization);
                                                    updateRows();
                                                    if (listAdapter != null) {
                                                        listAdapter.notifyDataSetChanged();
                                                    }
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
        }
    });

    return fragmentView;
}

From source file:com.cerema.cloud2.ui.activity.Uploader.java

@Override
protected Dialog onCreateDialog(final int id) {
    final AlertDialog.Builder builder = new Builder(this);
    switch (id) {
    case DIALOG_WAITING:
        final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme);
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading));
        pDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override/*from ww w. j a  v  a  2 s  .co m*/
            public void onShow(DialogInterface dialog) {
                ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress);
                v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.color_accent),
                        android.graphics.PorterDuff.Mode.MULTIPLY);

            }
        });
        return pDialog;
    case DIALOG_NO_ACCOUNT:
        builder.setIcon(R.drawable.ic_warning);
        builder.setTitle(R.string.uploader_wrn_no_account_title);
        builder.setMessage(
                String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name)));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
                    // using string value since in API7 this
                    // constant is not defined
                    // in API7 < this constant is defined in
                    // Settings.ADD_ACCOUNT_SETTINGS
                    // and Settings.EXTRA_AUTHORITIES
                    Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
                    intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() });
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                } else {
                    // since in API7 there is no direct call for
                    // account setup, so we need to
                    // show our own AccountSetupAcricity, get
                    // desired results and setup
                    // everything for ourself
                    Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class);
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                }
            }
        });
        builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    case DIALOG_MULTIPLE_ACCOUNT:
        CharSequence ac[] = new CharSequence[mAccountManager
                .getAccountsByType(MainApp.getAccountType()).length];
        for (int i = 0; i < ac.length; ++i) {
            ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name,
                    false);
        }
        builder.setTitle(R.string.common_choose_account);
        builder.setItems(ac, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]);
                onAccountSet(mAccountWasRestored);
                dialog.dismiss();
                mAccountSelected = true;
                mAccountSelectionShowing = false;
            }
        });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                mAccountSelectionShowing = false;
                dialog.cancel();
                finish();
            }
        });
        return builder.create();
    case DIALOG_NO_STREAM:
        builder.setIcon(R.drawable.ic_warning);
        builder.setTitle(R.string.uploader_wrn_no_content_title);
        builder.setMessage(R.string.uploader_wrn_no_content_text);
        builder.setCancelable(false);
        builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    default:
        throw new IllegalArgumentException("Unknown dialog id: " + id);
    }
}

From source file:org.fossasia.phimpme.share.nextcloud.IndeterminateProgressDialog.java

/**
 * {@inheritDoc}/*from ww w .jav  a2  s.  c  o  m*/
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    /// create indeterminate progress dialog
    final ProgressDialog progressDialog = new ProgressDialog(getActivity(), R.style.ProgressDialogTheme);
    progressDialog.setIndeterminate(true);
    progressDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            ProgressBar v = (ProgressBar) progressDialog.findViewById(android.R.id.progress);
            v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.colorAccent),
                    android.graphics.PorterDuff.Mode.MULTIPLY);

        }
    });

    /// set message
    int messageId = getArguments().getInt(ARG_MESSAGE_ID, R.string.placeholder_sentence);
    progressDialog.setMessage(getString(messageId));

    /// set cancellation behavior
    boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE, false);
    if (!cancelable) {
        progressDialog.setCancelable(false);
        // disable the back button
        OnKeyListener keyListener = new OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    return true;
                }
                return false;
            }

        };
        progressDialog.setOnKeyListener(keyListener);
    }

    return progressDialog;
}

From source file:com.cerema.cloud2.ui.dialog.IndeterminateProgressDialog.java

/**
 * {@inheritDoc}//from  w ww .  jav a 2 s. c  o  m
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    /// create indeterminate progress dialog
    final ProgressDialog progressDialog = new ProgressDialog(getActivity(), R.style.ProgressDialogTheme);
    progressDialog.setIndeterminate(true);
    progressDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            ProgressBar v = (ProgressBar) progressDialog.findViewById(android.R.id.progress);
            v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.color_accent),
                    android.graphics.PorterDuff.Mode.MULTIPLY);

        }
    });

    /// set message
    int messageId = getArguments().getInt(ARG_MESSAGE_ID, R.string.placeholder_sentence);
    progressDialog.setMessage(getString(messageId));

    /// set cancellation behavior
    boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE, false);
    if (!cancelable) {
        progressDialog.setCancelable(false);
        // disable the back button
        OnKeyListener keyListener = new OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    return true;
                }
                return false;
            }

        };
        progressDialog.setOnKeyListener(keyListener);
    }

    return progressDialog;
}

From source file:org.telegram.ui.CacheControlActivity.java

private void cleanupFolders() {
    final ProgressDialog progressDialog = new ProgressDialog(getParentActivity());
    progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setCancelable(false);
    progressDialog.show();//from  www  .j  av a 2s. com
    Utilities.globalQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            boolean imagesCleared = false;
            for (int a = 0; a < 6; a++) {
                if (!clear[a]) {
                    continue;
                }
                int type = -1;
                int documentsMusicType = 0;
                if (a == 0) {
                    type = FileLoader.MEDIA_DIR_IMAGE;
                } else if (a == 1) {
                    type = FileLoader.MEDIA_DIR_VIDEO;
                } else if (a == 2) {
                    type = FileLoader.MEDIA_DIR_DOCUMENT;
                    documentsMusicType = 1;
                } else if (a == 3) {
                    type = FileLoader.MEDIA_DIR_DOCUMENT;
                    documentsMusicType = 2;
                } else if (a == 4) {
                    type = FileLoader.MEDIA_DIR_AUDIO;
                } else if (a == 5) {
                    type = FileLoader.MEDIA_DIR_CACHE;
                }
                if (type == -1) {
                    continue;
                }
                File file = FileLoader.getInstance().checkDirectory(type);
                if (file != null) {
                    try {
                        File[] array = file.listFiles();
                        if (array != null) {
                            for (int b = 0; b < array.length; b++) {
                                String name = array[b].getName().toLowerCase();
                                if (documentsMusicType == 1 || documentsMusicType == 2) {
                                    if (name.endsWith(".mp3") || name.endsWith(".m4a")) {
                                        if (documentsMusicType == 1) {
                                            continue;
                                        }
                                    } else if (documentsMusicType == 2) {
                                        continue;
                                    }
                                }
                                if (name.equals(".nomedia")) {
                                    continue;
                                }
                                if (array[b].isFile()) {
                                    array[b].delete();
                                }
                            }
                        }
                    } catch (Throwable e) {
                        FileLog.e("tmessages", e);
                    }
                }
                if (type == FileLoader.MEDIA_DIR_CACHE) {
                    cacheSize = getDirectorySize(
                            FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_CACHE),
                            documentsMusicType);
                    imagesCleared = true;
                } else if (type == FileLoader.MEDIA_DIR_AUDIO) {
                    audioSize = getDirectorySize(
                            FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_AUDIO),
                            documentsMusicType);
                } else if (type == FileLoader.MEDIA_DIR_DOCUMENT) {
                    if (documentsMusicType == 1) {
                        documentsSize = getDirectorySize(
                                FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_DOCUMENT),
                                documentsMusicType);
                    } else {
                        musicSize = getDirectorySize(
                                FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_DOCUMENT),
                                documentsMusicType);
                    }
                } else if (type == FileLoader.MEDIA_DIR_IMAGE) {
                    imagesCleared = true;
                    photoSize = getDirectorySize(
                            FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_IMAGE),
                            documentsMusicType);
                } else if (type == FileLoader.MEDIA_DIR_VIDEO) {
                    videoSize = getDirectorySize(
                            FileLoader.getInstance().checkDirectory(FileLoader.MEDIA_DIR_VIDEO),
                            documentsMusicType);
                }
            }
            final boolean imagesClearedFinal = imagesCleared;
            totalSize = cacheSize + videoSize + audioSize + photoSize + documentsSize + musicSize;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    if (imagesClearedFinal) {
                        ImageLoader.getInstance().clearMemory();
                    }
                    if (listAdapter != null) {
                        listAdapter.notifyDataSetChanged();
                    }
                    try {
                        progressDialog.dismiss();
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
            });
        }
    });
}

From source file:projekt.substratum.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    startService(new Intent(this, ThemeService.class));

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w  ww  .jav  a 2  s  .  co m*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);

    AccountHeader header = new AccountHeaderBuilder().withActivity(this)
            .withHeaderBackground(R.drawable.material_drawer_header_background).withProfileImagesVisible(false)
            .withSelectionListEnabledForSingleProfile(false).addProfiles(new ProfileDrawerItem()
                    .withName(getString(R.string.drawer_name)).withEmail(BuildConfig.VERSION_NAME))
            .withCurrentProfileHiddenInList(true).build();

    final LibsSupportFragment fragment = new LibsBuilder().supportFragment();

    if (References.checkOMS()) {
        drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(header)
                .withSavedInstance(savedInstanceState).withActionBarDrawerToggleAnimated(true)
                .addDrawerItems(
                        new PrimaryDrawerItem().withName(R.string.nav_home)
                                .withIcon(R.drawable.nav_theme_packs),
                        new PrimaryDrawerItem().withName(R.string.nav_overlays)
                                .withIcon(R.drawable.nav_overlays),
                        new PrimaryDrawerItem().withName(R.string.nav_bootanim)
                                .withIcon(R.drawable.nav_bootanim),
                        new PrimaryDrawerItem().withName(R.string.nav_fonts).withIcon(R.drawable.nav_fonts),
                        new PrimaryDrawerItem().withName(R.string.nav_sounds).withIcon(R.drawable.nav_sounds),
                        new SectionDrawerItem().withName(R.string.nav_section_header_utilities),
                        new PrimaryDrawerItem().withName(R.string.nav_overlay_manager)
                                .withIcon(R.drawable.nav_overlay_manager),
                        new PrimaryDrawerItem().withName(R.string.nav_manage).withIcon(R.drawable.nav_manage),
                        new PrimaryDrawerItem().withName(R.string.nav_priorities)
                                .withIcon(R.drawable.nav_drawer_priorities),
                        new PrimaryDrawerItem().withName(R.string.nav_backup_restore)
                                .withIcon(R.drawable.nav_drawer_profiles),
                        new SectionDrawerItem().withName(R.string.nav_section_header_more),
                        new SecondaryDrawerItem().withName(R.string.nav_troubleshooting)
                                .withIcon(R.drawable.nav_troubleshooting),
                        new SecondaryDrawerItem().withName(R.string.nav_team)
                                .withIcon(R.drawable.nav_drawer_team),
                        new SecondaryDrawerItem().withName(getString(R.string.nav_opensource))
                                .withIcon(R.drawable.nav_drawer_licenses),
                        new SecondaryDrawerItem().withName(R.string.nav_settings)
                                .withIcon(R.drawable.nav_drawer_settings))
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        if (drawerItem != null) {
                            switch (position) {
                            case 1:
                                if (drawerSelected != position) {
                                    switchFragment(((References.checkOMS()) ? getString(R.string.app_name)
                                            : getString(R.string.legacy_app_name)), "HomeFragment");
                                    drawerSelected = 1;
                                }
                                break;
                            case 2:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_overlays), "OverlaysFragment");
                                    drawerSelected = 2;
                                }
                                break;
                            case 3:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_bootanim), "BootAnimationsFragment");
                                    drawerSelected = 3;
                                }
                                break;
                            case 4:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_fonts), "FontsFragment");
                                    drawerSelected = 4;
                                }
                                break;
                            case 5:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_sounds), "SoundsFragment");
                                    drawerSelected = 5;
                                }
                                break;
                            case 7:
                                switchFragment(getString(R.string.nav_overlay_manager),
                                        "AdvancedManagerFragment");
                                drawerSelected = 7;
                                break;
                            case 8:
                                switchFragment(getString(R.string.nav_manage), "ManageFragment");
                                drawerSelected = 8;
                                break;
                            case 9:
                                switchFragment(getString(R.string.nav_priorities), "PriorityLoaderFragment");
                                drawerSelected = 9;
                                break;
                            case 10:
                                switchFragment(getString(R.string.nav_backup_restore), "ProfileFragment");
                                drawerSelected = 10;
                                break;
                            case 12:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_troubleshooting),
                                            "TroubleshootingFragment");
                                    drawerSelected = 12;
                                }
                                break;
                            case 13:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_team), "TeamFragment");
                                    drawerSelected = 13;
                                }
                                break;
                            case 14:
                                switchFragmentToLicenses(getString(R.string.nav_opensource), fragment);
                                drawerSelected = 14;
                                break;
                            case 15:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_settings), "SettingsFragment");
                                    drawerSelected = 15;
                                }
                                break;
                            }
                        }
                        return false;
                    }
                }).withSelectedItem(1).withSelectedItemByPosition(1).build();
    } else {
        drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(header)
                .withSavedInstance(savedInstanceState).withActionBarDrawerToggleAnimated(true)
                .addDrawerItems(
                        new PrimaryDrawerItem().withName(R.string.nav_home)
                                .withIcon(R.drawable.nav_theme_packs),
                        new PrimaryDrawerItem().withName(R.string.nav_overlays)
                                .withIcon(R.drawable.nav_overlays),
                        new PrimaryDrawerItem().withName(R.string.nav_sounds).withIcon(R.drawable.nav_sounds),

                        new SectionDrawerItem().withName(R.string.nav_section_header_utilities),
                        new PrimaryDrawerItem().withName(R.string.nav_overlay_manager)
                                .withIcon(R.drawable.nav_overlay_manager),
                        new PrimaryDrawerItem().withName(R.string.nav_manage).withIcon(R.drawable.nav_manage),
                        new PrimaryDrawerItem().withName(R.string.nav_backup_restore)
                                .withIcon(R.drawable.nav_drawer_profiles),

                        new SectionDrawerItem().withName(R.string.nav_section_header_more),
                        new SecondaryDrawerItem().withName(R.string.nav_troubleshooting)
                                .withIcon(R.drawable.nav_troubleshooting),
                        new SecondaryDrawerItem().withName(R.string.nav_team)
                                .withIcon(R.drawable.nav_drawer_team),
                        new SecondaryDrawerItem().withName(getString(R.string.nav_opensource))
                                .withIcon(R.drawable.nav_drawer_licenses),
                        new SecondaryDrawerItem().withName(R.string.nav_settings)
                                .withIcon(R.drawable.nav_drawer_settings))
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        if (drawerItem != null) {
                            switch (position) {
                            case 1:
                                if (drawerSelected != position) {
                                    switchFragment(((References.checkOMS()) ? getString(R.string.app_name)
                                            : getString(R.string.legacy_app_name)), "HomeFragment");
                                    drawerSelected = 1;
                                }
                                break;
                            case 2:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_overlays), "OverlaysFragment");
                                    drawerSelected = 2;
                                }
                                break;
                            case 3:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_sounds), "SoundsFragment");
                                    drawerSelected = 3;
                                }
                                break;
                            case 5:
                                switchFragment(getString(R.string.nav_overlay_manager),
                                        "AdvancedManagerFragment");
                                drawerSelected = 5;
                                break;
                            case 6:
                                switchFragment(getString(R.string.nav_manage), "ManageFragment");
                                drawerSelected = 6;
                                break;
                            case 7:
                                switchFragment(getString(R.string.nav_backup_restore), "ProfileFragment");
                                drawerSelected = 7;
                                break;
                            case 9:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_troubleshooting),
                                            "TroubleshootingFragment");
                                    drawerSelected = 10;
                                }
                                break;
                            case 10:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_team), "TeamFragment");
                                    drawerSelected = 10;
                                }
                                break;
                            case 11:
                                switchFragmentToLicenses(getString(R.string.nav_opensource), fragment);
                                drawerSelected = 11;
                                break;
                            case 12:
                                if (drawerSelected != position) {
                                    switchFragment(getString(R.string.nav_settings), "SettingsFragment");
                                    drawerSelected = 12;
                                }
                                break;
                            }
                        }
                        return false;
                    }
                }).withSelectedItem(1).withSelectedItemByPosition(1).build();
    }
    if (!Root.requestRootAccess()) {
        final ProgressDialog mProgressDialog = new ProgressDialog(this,
                R.style.SubstratumBuilder_ActivityTheme);
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.setCancelable(false);
        mProgressDialog.show();
        mProgressDialog.setContentView(R.layout.root_rejected_loader);

        final float radius = 5;
        final View decorView = getWindow().getDecorView();
        final View rootView = decorView.findViewById(android.R.id.content);
        final Drawable windowBackground = decorView.getBackground();

        BlurView blurView = (BlurView) mProgressDialog.findViewById(R.id.blurView);

        blurView.setupWith(rootView).windowBackground(windowBackground)
                .blurAlgorithm(new RenderScriptBlur(this, true)).blurRadius(radius);

        final TextView textView = (TextView) mProgressDialog.findViewById(R.id.timer);
        CountDownTimer Count = new CountDownTimer(5000, 1000) {
            public void onTick(long millisUntilFinished) {
                if ((millisUntilFinished / 1000) > 1) {
                    textView.setText(String.format(getString(R.string.root_rejected_timer_plural),
                            (millisUntilFinished / 1000) + ""));
                } else {
                    textView.setText(String.format(getString(R.string.root_rejected_timer_singular),
                            (millisUntilFinished / 1000) + ""));
                }

            }

            public void onFinish() {
                mProgressDialog.dismiss();
                finish();
            }
        };
        Count.start();
    }

    permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(),
            Manifest.permission.WRITE_EXTERNAL_STORAGE);
    permissionCheck2 = ContextCompat.checkSelfPermission(getApplicationContext(),
            Manifest.permission.READ_PHONE_STATE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!Settings.System.canWrite(getApplicationContext())) {
            Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
            intent.setData(Uri.parse("package:" + MainActivity.this.getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {
            Log.d("SubstratumLogger", "Substratum was granted " + "'android.permission.WRITE_SETTINGS' "
                    + "permissions for system runtime code execution.");
        }
    }

    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
        // permission already granted, allow the program to continue running
        File directory = new File(Environment.getExternalStorageDirectory(), "/.substratum/");
        if (!directory.exists()) {
            directory.mkdirs();
        }
        File cacheDirectory = new File(getCacheDir(), "/SubstratumBuilder/");
        if (!cacheDirectory.exists()) {
            cacheDirectory.mkdirs();
        }
        if (permissionCheck2 == PackageManager.PERMISSION_GRANTED) {
            // permission already granted, allow the program to continue running
            // Set the first option to start at app boot
            drawer.setSelectionAtPosition(1);
        } else {
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_PHONE_STATE },
                    PERMISSIONS_REQUEST_READ_PHONE_STATE);
        }
    } else {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
    }

    // Now, let's grab root on the helper
    Intent rootIntent = new Intent(Intent.ACTION_MAIN);
    rootIntent.setAction("masquerade.substratum.INITIALIZE");
    try {
        startActivity(rootIntent);
    } catch (RuntimeException re) {
        // Exception: At this point, Masquerade is not installed at all.
    }

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    if (References.checkOMS()) {
        if (!prefs.getBoolean("substratum_oms", true)) {
            Root.runCommand(
                    "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/.substratum/");
            Root.runCommand(
                    "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/substratum/");
            File directory = new File(Environment.getExternalStorageDirectory(), "/.substratum/");
            if (!directory.exists()) {
                directory.mkdirs();
            }
        }
    } else {
        if (prefs.getBoolean("substratum_oms", true)) {
            Root.runCommand(
                    "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/.substratum/");
            Root.runCommand(
                    "rm -r " + Environment.getExternalStorageDirectory().getAbsolutePath() + "/substratum/");
            File directory = new File(Environment.getExternalStorageDirectory(), "/.substratum/");
            if (!directory.exists()) {
                directory.mkdirs();
            }
        }
    }

    printFCMtoken();
}

From source file:org.alfresco.mobile.android.ui.operation.OperationWaitingDialogFragment.java

public Dialog onCreateDialog(final Bundle savedInstanceState) {
    if (getArguments() != null) {
        operationType = getArguments().getInt(ARGUMENT_TYPEID);
        intentId = getArguments().getString(ARGUMENT_INTENTID);
        iconId = getArguments().getInt(ARGUMENT_ICONID);
        title = getArguments().getString(ARGUMENT_TITLEID);
        message = getArguments().getString(ARGUMENT_MESSAGEID);
        parent = getArguments().getParcelable(ARGUMENT_NODEID);
        nbItems = getArguments().getInt(ARGUMENT_SIZE);
        operationId = getArguments().getString(ARGUMENT_OPERATIONID);
    }/*from   w  ww  .j  a  v  a  2  s. c  om*/

    ProgressDialog dialog = new ProgressDialog(getActivity());
    if (iconId == 0) {
        iconId = R.drawable.ic_application_logo;
    }
    dialog.setIcon(iconId);
    dialog.setTitle(title);
    if (message == null) {
        message = getString(R.string.waiting_operations);
    }
    dialog.setMessage(message);
    boolean indeterminate = true;
    if (nbItems > 0) {
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgress(0);
        dialog.setMax(nbItems);
        indeterminate = false;
    } else {
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    }
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (operationId != null) {
                        Operator.with(getActivity()).cancel(operationId);
                    }
                    dialog.dismiss();
                }
            });

    getActivity().getLoaderManager().restartLoader(this.hashCode(), null, this);

    return dialog;
}

From source file:com.synox.android.ui.activity.Uploader.java

@Override
protected Dialog onCreateDialog(final int id) {
    final AlertDialog.Builder builder = new Builder(this);
    switch (id) {
    case DIALOG_WAITING:
        final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme);
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading));
        pDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override//from w ww .  java 2  s .  c  om
            public void onShow(DialogInterface dialog) {
                ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress);
                v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.accent),
                        android.graphics.PorterDuff.Mode.MULTIPLY);

            }
        });
        return pDialog;
    case DIALOG_NO_ACCOUNT:
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setTitle(R.string.uploader_wrn_no_account_title);
        builder.setMessage(
                String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name)));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
                    // using string value since in API7 this
                    // constatn is not defined
                    // in API7 < this constatant is defined in
                    // Settings.ADD_ACCOUNT_SETTINGS
                    // and Settings.EXTRA_AUTHORITIES
                    Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
                    intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() });
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                } else {
                    // since in API7 there is no direct call for
                    // account setup, so we need to
                    // show our own AccountSetupAcricity, get
                    // desired results and setup
                    // everything for ourself
                    Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class);
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                }
            }
        });
        builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    case DIALOG_MULTIPLE_ACCOUNT:
        CharSequence ac[] = new CharSequence[mAccountManager
                .getAccountsByType(MainApp.getAccountType()).length];
        for (int i = 0; i < ac.length; ++i) {
            ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name,
                    false);
        }
        builder.setTitle(R.string.common_choose_account);
        builder.setItems(ac, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]);
                onAccountSet(mAccountWasRestored);
                dialog.dismiss();
                mAccountSelected = true;
                mAccountSelectionShowing = false;
            }
        });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                mAccountSelectionShowing = false;
                dialog.cancel();
                finish();
            }
        });
        return builder.create();
    case DIALOG_NO_STREAM:
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setTitle(R.string.uploader_wrn_no_content_title);
        builder.setMessage(R.string.uploader_wrn_no_content_text);
        builder.setCancelable(false);
        builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    default:
        throw new IllegalArgumentException("Unknown dialog id: " + id);
    }
}