Search in sources :

Example 51 with RequiresApi

use of android.support.annotation.RequiresApi in project Alerter by Tapadoo.

the class SwipeDismissTouchListener method performDismiss.

@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.
    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();
    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mCallbacks.onDismiss(mView, mToken);
            // Reset view presentation
            mView.setAlpha(1f);
            mView.setTranslationX(0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
        }
    });
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
        }
    });
    animator.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ViewGroup(android.view.ViewGroup) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator) RequiresApi(android.support.annotation.RequiresApi)

Example 52 with RequiresApi

use of android.support.annotation.RequiresApi in project CSCI3130 by T-Caines.

the class CourseViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_course_view);
    spinner = findViewById(R.id.viewSpinner);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (spinner.getSelectedItem().toString().equals("Show All")) {
                lock(true, false, false);
            } else if (spinner.getSelectedItem().toString().equals("Show Non-Conflicting")) {
                lock(false, true, false);
            } else if (spinner.getSelectedItem().toString().equals("Show Schedule")) {
                lock(false, false, true);
            }
        }

        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
        String uid = user.getUid();
        mDatabase = FirebaseDatabase.getInstance().getReference().child("USERDATA").child(uid);
    }
    firebaseAdapter = new FirebaseListAdapter<Course>(this, Course.class, R.layout.list_view, FirebaseDatabase.getInstance().getReference("COURSE").child(ApplicationData.term.getTerm())) {

        @Override
        protected void populateView(View v, Course model, int position) {
            TextView seats = (TextView) v.findViewById(R.id.seats);
            seats.setText(String.format("%s/%s", model.enrollment, model.seatsAvailable));
            TextView code = (TextView) v.findViewById(R.id.code);
            code.setText(model.faculty + model.courseID);
            TextView courseName = (TextView) v.findViewById(R.id.name);
            courseName.setText(model.courseName);
            TextView timeEnd = (TextView) v.findViewById(R.id.end);
            timeEnd.setText("" + model.timeEnd);
            TextView timeStart = (TextView) v.findViewById(R.id.start);
            timeStart.setText("" + model.timeStart);
            TextView days = (TextView) v.findViewById(R.id.days);
            // TODO: Right method to convert binary 10101 -> MWF
            days.setText("" + model.days);
        }
    };
    // Create list view
    listView = findViewById(R.id.list_view);
    listView.setAdapter(firebaseAdapter);
    switch(ApplicationData.term) {
        case FALL:
            RadioButton fallRB = findViewById(R.id.fall);
            fallRB.setChecked(true);
            break;
        case WINTER:
            RadioButton winterRB = findViewById(R.id.winter);
            winterRB.setChecked(true);
            break;
        case SUMMER:
            RadioButton summerRB = findViewById(R.id.summer);
            summerRB.setChecked(true);
            break;
    }
    // Set what happens when a list view item is clicked
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @RequiresApi(api = Build.VERSION_CODES.M)
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Grab selected item from firebase
            selectedCourse = firebaseAdapter.getItem(position);
            // If there is an item already selected, un-highlight
            if (previousSelectedView != null) {
                previousSelectedView.setBackgroundColor(getColor(R.color.defaultBackground));
            }
            // Used to unselect a course. Happens when you select the selected item.
            if (previousSelectedView == view) {
                previousSelectedView = null;
                selectedCourse = null;
                return;
            }
            // Highlight this item
            view.setBackgroundColor(getColor(R.color.colorBalanced));
            previousSelectedView = view;
        }
    });
    Button addButton = findViewById(R.id.addbutton);
    addButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (selectedCourse == null)
                return;
            if (!courseManager.capReached(selectedCourse, v)) {
                System.out.println("Adding failed");
            }
        }
    });
    Button dropButton = findViewById(R.id.dropbutton);
    dropButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (selectedCourse == null)
                return;
            if (selectedCourse.hasLab) {
                courseManager.dropLabContinue(selectedCourse, v);
            } else {
                courseManager.confirmDrop(selectedCourse, v);
            }
        }
    });
}
Also used : RadioButton(android.widget.RadioButton) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) RadioButton(android.widget.RadioButton) Button(android.widget.Button) RequiresApi(android.support.annotation.RequiresApi) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Course(ca.dal.cs.softeng.database.Course)

Example 53 with RequiresApi

use of android.support.annotation.RequiresApi in project ForPDA by RadiationX.

the class App method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    instance = this;
    long time = System.currentTimeMillis();
    ACRA.init(this);
    ACRA.getErrorReporter().putCustomData("USER_NICK", getPreferences().getString("auth.user.nick", "null"));
    RxJavaPlugins.setErrorHandler(throwable -> {
        Log.d("SUKA", "RxJavaPlugins errorHandler " + throwable);
        throwable.printStackTrace();
    });
    setTheme(isDarkTheme() ? R.style.DarkAppTheme : R.style.LightAppTheme);
    try {
        String inputHistory = getPreferences().getString("app.versions.history", "");
        String[] history = TextUtils.split(inputHistory, ";");
        int lastVNum = 0;
        boolean disorder = false;
        for (String version : history) {
            int vNum = Integer.parseInt(version);
            if (vNum < lastVNum) {
                disorder = true;
            }
            lastVNum = vNum;
        }
        Object vCode = BuildConfig.VERSION_CODE;
        String sVCode = "" + vCode;
        int nVCode = Integer.parseInt(sVCode);
        if (lastVNum < nVCode) {
            List<String> list = new ArrayList<>(Arrays.asList(history));
            list.add(Integer.toString(nVCode));
            getPreferences().edit().putString("app.versions.history", TextUtils.join(";", list)).apply();
        }
        if (disorder) {
            throw new Exception("Нарушение порядка версий!");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        ACRA.getErrorReporter().putCustomData("VERSIONS_HISTORY", getPreferences().getString("app.versions.history", ""));
        ACRA.getErrorReporter().handleException(ex);
    }
    ACRA.getErrorReporter().putCustomData("VERSIONS_HISTORY", getPreferences().getString("app.versions.history", ""));
    density = getResources().getDisplayMetrics().density;
    initImageLoader(this);
    px2 = getContext().getResources().getDimensionPixelSize(R.dimen.dp2);
    px4 = getContext().getResources().getDimensionPixelSize(R.dimen.dp4);
    px6 = getContext().getResources().getDimensionPixelSize(R.dimen.dp6);
    px8 = getContext().getResources().getDimensionPixelSize(R.dimen.dp8);
    px12 = getContext().getResources().getDimensionPixelSize(R.dimen.dp12);
    px14 = getContext().getResources().getDimensionPixelSize(R.dimen.dp14);
    px16 = getContext().getResources().getDimensionPixelSize(R.dimen.dp16);
    px20 = getContext().getResources().getDimensionPixelSize(R.dimen.dp20);
    px24 = getContext().getResources().getDimensionPixelSize(R.dimen.dp24);
    px32 = getContext().getResources().getDimensionPixelSize(R.dimen.dp32);
    px36 = getContext().getResources().getDimensionPixelSize(R.dimen.dp36);
    px40 = getContext().getResources().getDimensionPixelSize(R.dimen.dp40);
    px48 = getContext().getResources().getDimensionPixelSize(R.dimen.dp48);
    px56 = getContext().getResources().getDimensionPixelSize(R.dimen.dp56);
    px64 = getContext().getResources().getDimensionPixelSize(R.dimen.dp64);
    for (Field f : R.string.class.getFields()) {
        try {
            if (f.getName().contains("res_s_")) {
                templateStringCache.put(f.getName(), getString(f.getInt(f)));
            }
        } catch (Exception ignore) {
        }
    }
    keyboardHeight = getPreferences().getInt("keyboard_height", getContext().getResources().getDimensionPixelSize(R.dimen.default_keyboard_height));
    savedKeyboardHeight = keyboardHeight;
    Realm.init(this);
    RealmConfiguration configuration = new RealmConfiguration.Builder().name("forpda.realm").schemaVersion(4).migration(new DbMigration()).build();
    Realm.setDefaultConfiguration(configuration);
    Client.get(getContext());
    getPreferences().registerOnSharedPreferenceChangeListener(preferenceChangeListener);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        BroadcastReceiver receiver = new BroadcastReceiver() {

            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void onReceive(Context context, Intent intent) {
                Log.d(App.class.getSimpleName(), "DOZE ON RECEIVE " + intent);
                PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                if (pm == null)
                    return;
                if (pm.isDeviceIdleMode()) {
                    // the device is now in doze mode
                    Log.d(App.class.getSimpleName(), "DOZE MODE ENABLYA");
                } else {
                    // the device just woke up from doze mode
                    Log.d(App.class.getSimpleName(), "DOZE MODE DISABLYA");
                    NotificationsService.startAndCheck();
                }
            }
        };
        registerReceiver(receiver, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
    }
    IntentFilter wakeUpFilter = new IntentFilter();
    wakeUpFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
    wakeUpFilter.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(new WakeUpReceiver(), wakeUpFilter);
    // На каких-то диких калькуляторах может быть ANR, поэтому в фоновый поток
    Observable.fromCallable(() -> {
        JobConfig.addLogger((priority, tag, message, t) -> {
            Log.e("JobLogger", "Job: pr=" + priority + "; t=" + tag + "; m=" + message + "; th=" + t);
        });
        JobConfig.setLogcatEnabled(false);
        JobManager.create(this).addJobCreator(new NotificationsJobCreator());
        JobManager.instance().cancelAllForTag(NotificationsJob.TAG);
        new JobRequest.Builder(NotificationsJob.TAG).setPeriodic(TimeUnit.MINUTES.toMillis(16L)).setRequiresCharging(false).setRequiresDeviceIdle(false).setRequiredNetworkType(JobRequest.NetworkType.ANY).build().schedule();
        return true;
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe();
    QmsHelper.init();
    Log.e("APP", "TIME APP FINAL " + (System.currentTimeMillis() - time));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Observer(java.util.Observer) Arrays(java.util.Arrays) PackageManager(android.content.pm.PackageManager) TabNotification(forpdateam.ru.forpda.data.models.TabNotification) Drawable(android.graphics.drawable.Drawable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) IBinder(android.os.IBinder) Preferences(forpdateam.ru.forpda.common.Preferences) Manifest(android.Manifest) PowerManager(android.os.PowerManager) ACRA(org.acra.ACRA) ByteArrayInputStream(java.io.ByteArrayInputStream) Handler(android.os.Handler) Map(java.util.Map) ServiceConnection(android.content.ServiceConnection) AttrRes(android.support.annotation.AttrRes) TabFragment(forpdateam.ru.forpda.ui.fragments.TabFragment) Schedulers(io.reactivex.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) Log(android.util.Log) JobConfig(com.evernote.android.job.JobConfig) Realm(io.realm.Realm) IntentFilter(android.content.IntentFilter) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration) RxJavaPlugins(io.reactivex.plugins.RxJavaPlugins) BroadcastReceiver(android.content.BroadcastReceiver) ActivityCompat(android.support.v4.app.ActivityCompat) APP_VERSION_NAME(org.acra.ReportField.APP_VERSION_NAME) DisplayMetrics(android.util.DisplayMetrics) ANDROID_VERSION(org.acra.ReportField.ANDROID_VERSION) List(java.util.List) NotificationsJobCreator(forpdateam.ru.forpda.notifications.NotificationsJobCreator) RealmConfiguration(io.realm.RealmConfiguration) UsingFreqLimitedMemoryCache(com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache) Pattern(java.util.regex.Pattern) USER_APP_START_DATE(org.acra.ReportField.USER_APP_START_DATE) STACK_TRACE(org.acra.ReportField.STACK_TRACE) MiniTemplator(biz.source_code.miniTemplator.MiniTemplator) Context(android.content.Context) JobRequest(com.evernote.android.job.JobRequest) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) ReportsCrashes(org.acra.annotation.ReportsCrashes) OnSharedPreferenceChangeListener(android.content.SharedPreferences.OnSharedPreferenceChangeListener) HashCodeFileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull) APP_VERSION_CODE(org.acra.ReportField.APP_VERSION_CODE) CustomCrashDialog(forpdateam.ru.forpda.ui.activities.CustomCrashDialog) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) LocaleHelper(forpdateam.ru.forpda.common.LocaleHelper) Cookie(okhttp3.Cookie) WebSettings(android.webkit.WebSettings) Charset(java.nio.charset.Charset) QmsHelper(forpdateam.ru.forpda.ui.fragments.qms.QmsHelper) CUSTOM_DATA(org.acra.ReportField.CUSTOM_DATA) VectorDrawable(android.graphics.drawable.VectorDrawable) Toast(android.widget.Toast) Client(forpdateam.ru.forpda.client.Client) Observable(io.reactivex.Observable) Build(android.os.Build) DbMigration(forpdateam.ru.forpda.common.realm.DbMigration) NotificationsJob(forpdateam.ru.forpda.notifications.NotificationsJob) WakeUpReceiver(forpdateam.ru.forpda.common.receivers.WakeUpReceiver) ComponentName(android.content.ComponentName) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer) TextUtils(android.text.TextUtils) BaseImageDownloader(com.nostra13.universalimageloader.core.download.BaseImageDownloader) IOException(java.io.IOException) Messenger(android.os.Messenger) AppCompatResources(android.support.v7.content.res.AppCompatResources) ImageLoader(com.nostra13.universalimageloader.core.ImageLoader) Field(java.lang.reflect.Field) LOGCAT(org.acra.ReportField.LOGCAT) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions) PHONE_MODEL(org.acra.ReportField.PHONE_MODEL) Color(android.graphics.Color) ColorInt(android.support.annotation.ColorInt) TimeUnit(java.util.concurrent.TimeUnit) ReportingInteractionMode(org.acra.ReportingInteractionMode) DrawableRes(android.support.annotation.DrawableRes) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) Bitmap(android.graphics.Bitmap) NotificationsService(forpdateam.ru.forpda.notifications.NotificationsService) JobManager(com.evernote.android.job.JobManager) Activity(android.app.Activity) InputStream(java.io.InputStream) SimpleObservable(forpdateam.ru.forpda.common.simple.SimpleObservable) ArrayList(java.util.ArrayList) NotificationsJobCreator(forpdateam.ru.forpda.notifications.NotificationsJobCreator) PowerManager(android.os.PowerManager) Field(java.lang.reflect.Field) RealmConfiguration(io.realm.RealmConfiguration) JobRequest(com.evernote.android.job.JobRequest) DbMigration(forpdateam.ru.forpda.common.realm.DbMigration) Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) IOException(java.io.IOException) WakeUpReceiver(forpdateam.ru.forpda.common.receivers.WakeUpReceiver)

Example 54 with RequiresApi

use of android.support.annotation.RequiresApi in project toshi-android-client by toshiapp.

the class ChatNotificationManager method buildDirectReplyAction.

@RequiresApi(24)
private static NotificationCompat.Action buildDirectReplyAction(final ChatNotification activeChatNotification) {
    final String messageLabel = BaseApplication.get().getString(R.string.message);
    final RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(messageLabel).build();
    return new NotificationCompat.Action.Builder(R.drawable.ic_send, messageLabel, activeChatNotification.getDirectReplyIntent()).addRemoteInput(remoteInput).build();
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) NotificationCompat(android.support.v4.app.NotificationCompat) RequiresApi(android.support.annotation.RequiresApi)

Example 55 with RequiresApi

use of android.support.annotation.RequiresApi in project toshi-android-client by toshiapp.

the class ToshiNotificationBuilder method createPaymentsChannel.

@RequiresApi(api = 26)
private static NotificationChannel createPaymentsChannel() {
    final String id = String.valueOf(SofaType.PAYMENT);
    final NotificationChannel notificationChannel = new NotificationChannel(id, PAYMENTS_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
    return addNotificationAttributes(notificationChannel);
}
Also used : NotificationChannel(android.app.NotificationChannel) RequiresApi(android.support.annotation.RequiresApi)

Aggregations

RequiresApi (android.support.annotation.RequiresApi)191 Intent (android.content.Intent)30 NotificationChannel (android.app.NotificationChannel)28 View (android.view.View)25 NotificationManager (android.app.NotificationManager)17 ViewGroup (android.view.ViewGroup)15 Allocation (android.renderscript.Allocation)14 Bitmap (android.graphics.Bitmap)13 RecyclerView (android.support.v7.widget.RecyclerView)13 ViewTreeObserver (android.view.ViewTreeObserver)12 WindowInsets (android.view.WindowInsets)12 TextView (android.widget.TextView)12 ActionBar (android.support.v7.app.ActionBar)11 Toolbar (android.support.v7.widget.Toolbar)11 Handler (android.os.Handler)10 StatFs (android.os.StatFs)9 Button (android.widget.Button)8 Cipher (javax.crypto.Cipher)8 SuppressLint (android.annotation.SuppressLint)7 Uri (android.net.Uri)7