Search in sources :

Example 21 with AppCompatTextView

use of android.support.v7.widget.AppCompatTextView in project Rashr by DsLNeXuS.

the class RashrActivity method onRequestPermissionsResult.

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    // If request is cancelled, the result arrays are empty.
    if (// 2 Permissions, Internet and Write storage
    grantResults.length == 2 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
        final TextView tvLoading = findViewById(R.id.tvLoading);
        final Thread StartThread = new Thread(new Runnable() {

            @Override
            public void run() {
                /* Creating needed folder and unpacking files */
                mActivity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        tvLoading.setText(R.string.loading_data);
                    }
                });
                if (App.PathToTmp.exists()) {
                    Common.deleteFolder(App.PathToTmp, true);
                }
                for (File i : Folder) {
                    if (!i.exists()) {
                        if (!i.mkdirs()) {
                            App.ERRORS.add(App.TAG + " " + i + " can't be created!");
                        }
                    }
                }
                if (!extractFiles()) {
                    App.ERRORS.add("Failed to extract files.");
                    mActivity.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(mContext, R.string.failed_unpack_files, Toast.LENGTH_LONG).show();
                        }
                    });
                }
                try {
                    File LogCopy = new File(App.FilesDir, App.LastLog.getName() + ".txt");
                    App.Shell.execCommand(App.Busybox + " chmod 777 " + App.LastLog);
                    if (LogCopy.exists())
                        LogCopy.delete();
                    App.Shell.execCommand(App.Busybox + " cp " + App.LastLog + " " + LogCopy);
                    App.Shell.execCommand(App.Busybox + " chmod 777 " + LogCopy);
                    ApplicationInfo info = getApplicationInfo();
                    App.Shell.execCommand(App.Busybox + " chown " + info.uid + ":" + info.uid + " " + LogCopy);
                    App.Shell.execCommand(App.Busybox + " chmod 777 " + LogCopy);
                    LastLogExists = LogCopy.exists();
                } catch (FailedExecuteCommand e) {
                    App.ERRORS.add(App.TAG + " LastLog not found: " + e);
                }
                mActivity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        checkAppUpdates();
                        tvLoading.setText(R.string.reading_device);
                    }
                });
                if (!App.Device.isSetup()) {
                    App.Device.setup();
                }
                /* If device is not supported, you can report it now or close the App */
                if ((!App.Device.isRecoverySupported() && !App.Device.isKernelSupported()) && !BuildConfig.DEBUG) {
                    mActivity.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            showDeviceNotSupportedDialog();
                        }
                    });
                } else {
                    /* App is first time started so show usage warning */
                    if (App.Preferences.getBoolean(App.PREF_KEY_FIRST_RUN, true)) {
                        mActivity.runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                if (App.Device.isRecoverySupported() || App.Device.isKernelSupported()) {
                                    // Show only if we can flash
                                    showUsageWarning();
                                }
                            }
                        });
                    }
                }
                mActivity.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            mRoot = (DrawerLayout) View.inflate(mContext, R.layout.activity_rashr, null);
                            setContentView(mRoot);
                            ButterKnife.bind(mActivity);
                            mRoot.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.abc_fade_in));
                            mToolbar = findViewById(R.id.toolbar);
                            setSupportActionBar(mToolbar);
                            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(mActivity, mRoot, mToolbar, R.string.app_name, R.string.app_name);
                            // Coloring drawertoggle
                            DrawerArrowDrawable coloredArrow = new DrawerArrowDrawable(mContext);
                            TypedValue typedValue = new TypedValue();
                            Resources.Theme theme = getTheme();
                            theme.resolveAttribute(R.attr.colorAccent, typedValue, true);
                            coloredArrow.setColor(typedValue.data);
                            toggle.setDrawerArrowDrawable(coloredArrow);
                            mRoot.addDrawerListener(toggle);
                            toggle.syncState();
                            mNavigationView.setNavigationItemSelectedListener(mActivity);
                            if (mAds != null) {
                                if (App.Preferences.getBoolean(App.PREF_KEY_ADS, true)) {
                                    mAds.loadAd(new AdRequest.Builder().addTestDevice("BB1FFBF880370A581E6665C69C97D711").build());
                                } else {
                                    mAds.setVisibility(View.GONE);
                                    mRoot.removeView(mAds);
                                }
                            }
                            if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
                                /* Rashr is opened by other app to flash supported files (.zip) or (.img) */
                                File file = new File(getIntent().getData().getPath());
                                if (file.exists()) {
                                    if (file.toString().endsWith(Device.EXT_ZIP)) {
                                        /* If it is a zip file open the ScriptManager */
                                        switchTo(ScriptManagerFragment.newInstance(file));
                                    } else if (file.toString().endsWith(Device.EXT_IMG)) {
                                        /* If it is a img file open FlashAs to choose mode (recovery or kernel) */
                                        switchTo(FlashAsFragment.newInstance(mActivity, file));
                                    }
                                }
                            } else {
                                onNavigationItemSelected(mNavigationView.getMenu().getItem(0));
                            }
                        } catch (NullPointerException e) {
                            setContentView(R.layout.err_layout);
                            App.ERRORS.add("Error while inflating layout:" + e);
                            AppCompatTextView tv = findViewById(R.id.tvErr);
                            try {
                                if (tv != null) {
                                    tv.setText(R.string.failed_setup_layout);
                                }
                            } catch (RuntimeException ex) {
                                App.ERRORS.add(App.TAG + " " + e);
                                ReportDialog dialog = new ReportDialog(mActivity, e.toString());
                                dialog.show();
                                ex.printStackTrace();
                            }
                            ReportDialog dialog = new ReportDialog(mActivity, e.toString());
                            dialog.show();
                            e.printStackTrace();
                        }
                    }
                });
            }
        });
        StartThread.start();
    } else {
        // Permission not garanted
        setContentView(R.layout.err_layout);
        AppCompatTextView tverr = findViewById(R.id.tvErr);
        tverr.setText(R.string.permissions_denied);
    }
}
Also used : FailedExecuteCommand(org.sufficientlysecure.rootcommands.util.FailedExecuteCommand) ApplicationInfo(android.content.pm.ApplicationInfo) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) AppCompatTextView(android.support.v7.widget.AppCompatTextView) AdRequest(com.google.android.gms.ads.AdRequest) DrawerArrowDrawable(android.support.v7.graphics.drawable.DrawerArrowDrawable) AppCompatTextView(android.support.v7.widget.AppCompatTextView) TextView(android.widget.TextView) Resources(android.content.res.Resources) File(java.io.File) TypedValue(android.util.TypedValue)

Aggregations

AppCompatTextView (android.support.v7.widget.AppCompatTextView)20 View (android.view.View)10 AppCompatButton (android.support.v7.widget.AppCompatButton)4 Espresso.onView (android.support.test.espresso.Espresso.onView)3 MediumTest (android.support.test.filters.MediumTest)3 ViewGroup (android.view.ViewGroup)3 TextView (android.widget.TextView)3 File (java.io.File)3 Test (org.junit.Test)3 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 RecyclerView (android.support.v7.widget.RecyclerView)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 Resources (android.content.res.Resources)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 TestFloatingBehavior (android.support.design.testapp.custom.TestFloatingBehavior)1 ActionBar (android.support.v7.app.ActionBar)1