Search in sources :

Example 1 with SuperActivityToast

use of com.github.johnpersano.supertoasts.SuperActivityToast in project CoCoin by Nightonke.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mContext = this;
    //        Bmob.initialize(CoCoinApplication.getAppContext(), CoCoin.APPLICATION_ID);
    //        CrashReport.initCrashReport(CoCoinApplication.getAppContext(), "900016815", false);
    //        RecordManager.getInstance(CoCoinApplication.getAppContext());
    //        CoCoinUtil.init(CoCoinApplication.getAppContext());
    appUpdateManager = new AppUpdateManager(mContext);
    appUpdateManager.checkUpdateInfo(false);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    Sensor magneticSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    sensorManager.registerListener(listener, magneticSensor, SensorManager.SENSOR_DELAY_GAME);
    sensorManager.registerListener(listener, accelerometerSensor, SensorManager.SENSOR_DELAY_GAME);
    superToast = new SuperToast(this);
    superActivityToast = new SuperActivityToast(this, SuperToast.Type.PROGRESS_HORIZONTAL);
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    Log.d("Saver", "Version number: " + currentapiVersion);
    if (currentapiVersion >= Build.VERSION_CODES.LOLLIPOP) {
        // Do something for lollipop and above versions
        Window window = this.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(ContextCompat.getColor(mContext, R.color.statusBarColor));
    } else {
    // do something for phones running an SDK before lollipop
    }
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        SettingManager.getInstance().setLoggenOn(true);
        SettingManager.getInstance().setUserName(user.getUsername());
        SettingManager.getInstance().setUserEmail(user.getEmail());
        showToast(WELCOME_BACK);
    // 允许用户使用应用
    } else {
        SettingManager.getInstance().setLoggenOn(false);
    //缓存用户对象为空时, 可打开用户注册界面…
    }
    guillotineBackground = findViewById(R.id.guillotine_background);
    toolBarTitle = (TextView) findViewById(R.id.guillotine_title);
    toolBarTitle.setTypeface(CoCoinUtil.typefaceLatoLight);
    toolBarTitle.setText(SettingManager.getInstance().getAccountBookName());
    // edit viewpager///////////////////////////////////////////////////////////////////////////////////
    editViewPager = (CoCoinScrollableViewPager) findViewById(R.id.edit_pager);
    editAdapter = new EditMoneyRemarkFragmentAdapter(getSupportFragmentManager(), CoCoinFragmentManager.MAIN_ACTIVITY_FRAGMENT);
    editViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (position == 1) {
                if (CoCoinFragmentManager.mainActivityEditRemarkFragment != null)
                    CoCoinFragmentManager.mainActivityEditRemarkFragment.editRequestFocus();
            } else {
                if (CoCoinFragmentManager.mainActivityEditMoneyFragment != null)
                    CoCoinFragmentManager.mainActivityEditMoneyFragment.editRequestFocus();
            }
        }

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    editViewPager.setAdapter(editAdapter);
    // tag viewpager////////////////////////////////////////////////////////////////////////////////////
    tagViewPager = (ViewPager) findViewById(R.id.viewpager);
    if (RecordManager.getInstance(mContext).TAGS.size() % 8 == 0)
        tagAdapter = new TagChooseFragmentAdapter(getSupportFragmentManager(), RecordManager.TAGS.size() / 8);
    else
        tagAdapter = new TagChooseFragmentAdapter(getSupportFragmentManager(), RecordManager.TAGS.size() / 8 + 1);
    tagViewPager.setAdapter(tagAdapter);
    // button grid view/////////////////////////////////////////////////////////////////////////////////
    myGridView = (MyGridView) findViewById(R.id.gridview);
    myGridViewAdapter = new ButtonGridViewAdapter(this);
    myGridView.setAdapter(myGridViewAdapter);
    myGridView.setOnItemClickListener(gridViewClickListener);
    myGridView.setOnItemLongClickListener(gridViewLongClickListener);
    myGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            myGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            View lastChild = myGridView.getChildAt(myGridView.getChildCount() - 1);
            myGridView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, lastChild.getBottom()));
            ViewGroup.LayoutParams params = transparentLy.getLayoutParams();
            params.height = myGridView.getMeasuredHeight();
        }
    });
    ButterKnife.inject(this);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(null);
    }
    toolbar.hideOverflowMenu();
    guillotineMenu = LayoutInflater.from(this).inflate(R.layout.guillotine, null);
    root.addView(guillotineMenu);
    transparentLy = (LinearLayout) guillotineMenu.findViewById(R.id.transparent_ly);
    guillotineColorLy = (LinearLayout) guillotineMenu.findViewById(R.id.guillotine_color_ly);
    guillotineToolBar = (Toolbar) guillotineMenu.findViewById(R.id.toolbar);
    menuToolBarTitle = (TextView) guillotineMenu.findViewById(R.id.guillotine_title);
    menuToolBarTitle.setTypeface(CoCoinUtil.typefaceLatoLight);
    menuToolBarTitle.setText(SettingManager.getInstance().getAccountBookName());
    radioButton0 = (RadioButton) guillotineMenu.findViewById(R.id.radio_button_0);
    radioButton1 = (RadioButton) guillotineMenu.findViewById(R.id.radio_button_1);
    radioButton2 = (RadioButton) guillotineMenu.findViewById(R.id.radio_button_2);
    radioButton3 = (RadioButton) guillotineMenu.findViewById(R.id.radio_button_3);
    passwordTip = (TextView) guillotineMenu.findViewById(R.id.password_tip);
    passwordTip.setText(mContext.getResources().getString(R.string.password_tip));
    passwordTip.setTypeface(CoCoinUtil.typefaceLatoLight);
    radioButtonLy = (LinearLayout) guillotineMenu.findViewById(R.id.radio_button_ly);
    statusButton = (MaterialMenuView) guillotineMenu.findViewById(R.id.status_button);
    statusButton.setState(MaterialMenuDrawable.IconState.ARROW);
    statusButton.setOnClickListener(statusButtonOnClickListener);
    animation = new GuillotineAnimation.GuillotineBuilder(guillotineMenu, guillotineMenu.findViewById(R.id.guillotine_hamburger), contentHamburger).setStartDelay(RIPPLE_DURATION).setActionBarViewForAnimation(toolbar).setClosedOnStart(true).setGuillotineListener(new GuillotineListener() {

        @Override
        public void onGuillotineOpened() {
            isPassword = true;
        }

        @Override
        public void onGuillotineClosed() {
            isPassword = false;
            CoCoinFragmentManager.mainActivityEditMoneyFragment.editRequestFocus();
            radioButton0.setChecked(false);
            radioButton1.setChecked(false);
            radioButton2.setChecked(false);
            radioButton3.setChecked(false);
            inputPassword = "";
            statusButton.setState(MaterialMenuDrawable.IconState.ARROW);
        }
    }).build();
    toolbar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            animation.open();
        }
    });
    if (SettingManager.getInstance().getFirstTime()) {
        Intent intent = new Intent(mContext, ShowActivity.class);
        startActivity(intent);
    }
    if (SettingManager.getInstance().getShowMainActivityGuide()) {
        boolean wrapInScrollView = true;
        new MaterialDialog.Builder(this).title(R.string.guide).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).customView(R.layout.main_activity_guide, wrapInScrollView).positiveText(R.string.ok).show();
        SettingManager.getInstance().setShowMainActivityGuide(false);
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) SuperToast(com.github.johnpersano.supertoasts.SuperToast) ButtonGridViewAdapter(com.nightonke.saver.adapter.ButtonGridViewAdapter) ViewTreeObserver(android.view.ViewTreeObserver) TagChooseFragmentAdapter(com.nightonke.saver.adapter.TagChooseFragmentAdapter) Window(android.view.Window) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SuperActivityToast(com.github.johnpersano.supertoasts.SuperActivityToast) Intent(android.content.Intent) ViewPager(android.support.v4.view.ViewPager) CoCoinScrollableViewPager(com.nightonke.saver.ui.CoCoinScrollableViewPager) InjectView(butterknife.InjectView) View(android.view.View) MyGridView(com.nightonke.saver.ui.MyGridView) AdapterView(android.widget.AdapterView) MaterialMenuView(com.balysv.materialmenu.MaterialMenuView) TextView(android.widget.TextView) AppUpdateManager(com.nightonke.saver.model.AppUpdateManager) EditMoneyRemarkFragmentAdapter(com.nightonke.saver.adapter.EditMoneyRemarkFragmentAdapter) GuillotineListener(com.nightonke.saver.ui.guillotine.interfaces.GuillotineListener) Sensor(android.hardware.Sensor)

Example 2 with SuperActivityToast

use of com.github.johnpersano.supertoasts.SuperActivityToast in project FBReaderJ by geometer.

the class ProcessHyperlinkAction method run.

@Override
protected void run(Object... params) {
    final ZLTextRegion region = Reader.getTextView().getOutlinedRegion();
    if (region == null) {
        return;
    }
    final ZLTextRegion.Soul soul = region.getSoul();
    if (soul instanceof ZLTextHyperlinkRegionSoul) {
        Reader.getTextView().hideOutline();
        Reader.getViewWidget().repaint();
        final ZLTextHyperlink hyperlink = ((ZLTextHyperlinkRegionSoul) soul).Hyperlink;
        switch(hyperlink.Type) {
            case FBHyperlinkType.EXTERNAL:
                openInBrowser(hyperlink.Id);
                break;
            case FBHyperlinkType.INTERNAL:
            case FBHyperlinkType.FOOTNOTE:
                {
                    final AutoTextSnippet snippet = Reader.getFootnoteData(hyperlink.Id);
                    if (snippet == null) {
                        break;
                    }
                    Reader.Collection.markHyperlinkAsVisited(Reader.getCurrentBook(), hyperlink.Id);
                    final boolean showToast;
                    switch(Reader.MiscOptions.ShowFootnoteToast.getValue()) {
                        default:
                        case never:
                            showToast = false;
                            break;
                        case footnotesOnly:
                            showToast = hyperlink.Type == FBHyperlinkType.FOOTNOTE;
                            break;
                        case footnotesAndSuperscripts:
                            showToast = hyperlink.Type == FBHyperlinkType.FOOTNOTE || region.isVerticallyAligned();
                            break;
                        case allInternalLinks:
                            showToast = true;
                            break;
                    }
                    if (showToast) {
                        final SuperActivityToast toast;
                        if (snippet.IsEndOfText) {
                            toast = new SuperActivityToast(BaseActivity, SuperToast.Type.STANDARD);
                        } else {
                            toast = new SuperActivityToast(BaseActivity, SuperToast.Type.BUTTON);
                            toast.setButtonIcon(android.R.drawable.ic_menu_more, ZLResource.resource("toast").getResource("more").getValue());
                            toast.setOnClickWrapper(new OnClickWrapper("ftnt", new SuperToast.OnClickListener() {

                                @Override
                                public void onClick(View view, Parcelable token) {
                                    Reader.getTextView().hideOutline();
                                    Reader.tryOpenFootnote(hyperlink.Id);
                                }
                            }));
                        }
                        toast.setText(snippet.getText());
                        toast.setDuration(Reader.MiscOptions.FootnoteToastDuration.getValue().Value);
                        toast.setOnDismissWrapper(new OnDismissWrapper("ftnt", new SuperToast.OnDismissListener() {

                            @Override
                            public void onDismiss(View view) {
                                Reader.getTextView().hideOutline();
                                Reader.getViewWidget().repaint();
                            }
                        }));
                        Reader.getTextView().outlineRegion(region);
                        BaseActivity.showToast(toast);
                    } else {
                        Reader.tryOpenFootnote(hyperlink.Id);
                    }
                    break;
                }
        }
    } else if (soul instanceof ZLTextImageRegionSoul) {
        Reader.getTextView().hideOutline();
        Reader.getViewWidget().repaint();
        final String url = ((ZLTextImageRegionSoul) soul).ImageElement.URL;
        if (url != null) {
            try {
                final Intent intent = new Intent();
                intent.setClass(BaseActivity, ImageViewActivity.class);
                intent.putExtra(ImageViewActivity.URL_KEY, url);
                intent.putExtra(ImageViewActivity.BACKGROUND_COLOR_KEY, Reader.ImageOptions.ImageViewBackground.getValue().intValue());
                OrientationUtil.startActivity(BaseActivity, intent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } else if (soul instanceof ZLTextWordRegionSoul) {
        DictionaryUtil.openTextInDictionary(BaseActivity, ((ZLTextWordRegionSoul) soul).Word.getString(), true, region.getTop(), region.getBottom(), new Runnable() {

            public void run() {
                BaseActivity.outlineRegion(soul);
            }
        });
    }
}
Also used : SuperToast(com.github.johnpersano.supertoasts.SuperToast) ImageViewActivity(org.geometerplus.android.fbreader.image.ImageViewActivity) SuperActivityToast(com.github.johnpersano.supertoasts.SuperActivityToast) Parcelable(android.os.Parcelable) Intent(android.content.Intent) View(android.view.View) AutoTextSnippet(org.geometerplus.fbreader.util.AutoTextSnippet) ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) ActivityNotFoundException(android.content.ActivityNotFoundException) OnClickWrapper(com.github.johnpersano.supertoasts.util.OnClickWrapper) OnDismissWrapper(com.github.johnpersano.supertoasts.util.OnDismissWrapper)

Example 3 with SuperActivityToast

use of com.github.johnpersano.supertoasts.SuperActivityToast in project FBReaderJ by geometer.

the class FBReaderMainActivity method hideToast.

public void hideToast() {
    final SuperActivityToast toast = myToast;
    if (toast != null && toast.isShowing()) {
        myToast = null;
        runOnUiThread(new Runnable() {

            public void run() {
                toast.dismiss();
            }
        });
    }
}
Also used : SuperActivityToast(com.github.johnpersano.supertoasts.SuperActivityToast)

Example 4 with SuperActivityToast

use of com.github.johnpersano.supertoasts.SuperActivityToast in project FBReaderJ by geometer.

the class Dictan method onActivityResult.

void onActivityResult(final FBReaderMainActivity fbreader, int resultCode, final Intent data) {
    if (data == null) {
        fbreader.hideDictionarySelection();
        return;
    }
    final int errorCode = data.getIntExtra("error.code", -1);
    if (resultCode != FBReaderMainActivity.RESULT_OK || errorCode != -1) {
        showError(fbreader, errorCode, data);
        return;
    }
    String text = data.getStringExtra("article.text");
    if (text == null) {
        showError(fbreader, -1, data);
        return;
    }
    // a hack for obsolete (before 5.0 beta) dictan versions
    final int index = text.indexOf("\000");
    if (index >= 0) {
        text = text.substring(0, index);
    }
    final boolean hasExtraData;
    if (text.length() == MAX_LENGTH_FOR_TOAST) {
        text = trimArticle(text);
        hasExtraData = true;
    } else {
        hasExtraData = data.getBooleanExtra("article.resources.contains", false);
    }
    final SuperActivityToast toast;
    if (hasExtraData) {
        toast = new SuperActivityToast(fbreader, SuperToast.Type.BUTTON);
        toast.setButtonIcon(android.R.drawable.ic_menu_more, ZLResource.resource("toast").getResource("more").getValue());
        toast.setOnClickWrapper(new OnClickWrapper("dict", new SuperToast.OnClickListener() {

            @Override
            public void onClick(View view, Parcelable token) {
                final String word = data.getStringExtra("article.word");
                final Intent intent = getActionIntent(word);
                try {
                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    fbreader.startActivity(intent);
                    fbreader.overridePendingTransition(0, 0);
                } catch (ActivityNotFoundException e) {
                // ignore
                }
            }
        }));
    } else {
        toast = new SuperActivityToast(fbreader, SuperToast.Type.STANDARD);
    }
    toast.setText(text);
    toast.setDuration(DictionaryUtil.TranslationToastDurationOption.getValue().Value);
    InternalUtil.showToast(toast, fbreader);
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) OnClickWrapper(com.github.johnpersano.supertoasts.util.OnClickWrapper) SuperActivityToast(com.github.johnpersano.supertoasts.SuperActivityToast) Parcelable(android.os.Parcelable) Intent(android.content.Intent) View(android.view.View)

Example 5 with SuperActivityToast

use of com.github.johnpersano.supertoasts.SuperActivityToast in project FBReaderJ by geometer.

the class SelectionBookmarkAction method run.

@Override
protected void run(Object... params) {
    final Bookmark bookmark;
    if (params.length != 0) {
        bookmark = (Bookmark) params[0];
    } else {
        bookmark = Reader.addSelectionBookmark();
    }
    if (bookmark == null) {
        return;
    }
    final SuperActivityToast toast = new SuperActivityToast(BaseActivity, SuperToast.Type.BUTTON);
    toast.setText(bookmark.getText());
    toast.setDuration(SuperToast.Duration.EXTRA_LONG);
    toast.setButtonIcon(android.R.drawable.ic_menu_edit, ZLResource.resource("dialog").getResource("button").getResource("edit").getValue());
    toast.setOnClickWrapper(new OnClickWrapper("bkmk", new SuperToast.OnClickListener() {

        @Override
        public void onClick(View view, Parcelable token) {
            final Intent intent = new Intent(BaseActivity.getApplicationContext(), EditBookmarkActivity.class);
            FBReaderIntents.putBookmarkExtra(intent, bookmark);
            OrientationUtil.startActivity(BaseActivity, intent);
        }
    }));
    BaseActivity.showToast(toast);
}
Also used : Bookmark(org.geometerplus.fbreader.book.Bookmark) OnClickWrapper(com.github.johnpersano.supertoasts.util.OnClickWrapper) SuperActivityToast(com.github.johnpersano.supertoasts.SuperActivityToast) Parcelable(android.os.Parcelable) Intent(android.content.Intent) View(android.view.View)

Aggregations

SuperActivityToast (com.github.johnpersano.supertoasts.SuperActivityToast)6 Intent (android.content.Intent)4 View (android.view.View)4 Parcelable (android.os.Parcelable)3 OnClickWrapper (com.github.johnpersano.supertoasts.util.OnClickWrapper)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 SuperToast (com.github.johnpersano.supertoasts.SuperToast)2 Sensor (android.hardware.Sensor)1 ViewPager (android.support.v4.view.ViewPager)1 ViewTreeObserver (android.view.ViewTreeObserver)1 Window (android.view.Window)1 AdapterView (android.widget.AdapterView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 BmobUser (cn.bmob.v3.BmobUser)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 MaterialMenuView (com.balysv.materialmenu.MaterialMenuView)1 OnDismissWrapper (com.github.johnpersano.supertoasts.util.OnDismissWrapper)1 ButtonGridViewAdapter (com.nightonke.saver.adapter.ButtonGridViewAdapter)1 EditMoneyRemarkFragmentAdapter (com.nightonke.saver.adapter.EditMoneyRemarkFragmentAdapter)1