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
17package com.android.camera.ui;
18
19import com.android.camera.R;
20import com.android.camera.Util;
21
22import android.app.Activity;
23import android.os.Handler;
24import android.view.LayoutInflater;
25import android.view.View;
26import android.view.ViewGroup;
27import android.widget.TextView;
28
29public 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);
43        mHandler = new Handler();
44    }
45
46    private final Runnable mRunnable = new Runnable() {
47        public void run() {
48            Util.fadeOut(mToast);
49            mLayoutRoot.removeView(mToast);
50            mToast = null;
51        }
52    };
53
54    public void show() {
55        mToast.setVisibility(View.VISIBLE);
56        mHandler.postDelayed(mRunnable, TOAST_DURATION);
57    }
58}
59