Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.camera.ui;
     18 
     19 import android.app.Activity;
     20 import android.os.Handler;
     21 import android.view.LayoutInflater;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 import android.widget.TextView;
     25 
     26 import com.android.camera.Util;
     27 import com.android.gallery3d.R;
     28 
     29 public class RotateTextToast {
     30     private static final int TOAST_DURATION = 5000; // milliseconds
     31     ViewGroup mLayoutRoot;
     32     RotateLayout mToast;
     33     Handler mHandler;
     34 
     35     public RotateTextToast(Activity activity, int textResourceId, int orientation) {
     36         mLayoutRoot = (ViewGroup) activity.getWindow().getDecorView();
     37         LayoutInflater inflater = activity.getLayoutInflater();
     38         View v = inflater.inflate(R.layout.rotate_text_toast, mLayoutRoot);
     39         mToast = (RotateLayout) v.findViewById(R.id.rotate_toast);
     40         TextView tv = (TextView) mToast.findViewById(R.id.message);
     41         tv.setText(textResourceId);
     42         mToast.setOrientation(orientation, false);
     43         mHandler = new Handler();
     44     }
     45 
     46     private final Runnable mRunnable = new Runnable() {
     47         @Override
     48         public void run() {
     49             Util.fadeOut(mToast);
     50             mLayoutRoot.removeView(mToast);
     51             mToast = null;
     52         }
     53     };
     54 
     55     public void show() {
     56         mToast.setVisibility(View.VISIBLE);
     57         mHandler.postDelayed(mRunnable, TOAST_DURATION);
     58     }
     59 }
     60