125668cd6ed661c59295cb65348a126fb245757d4Michael Kolb/*
225668cd6ed661c59295cb65348a126fb245757d4Michael Kolb * Copyright (C) 2011 The Android Open Source Project
325668cd6ed661c59295cb65348a126fb245757d4Michael Kolb *
425668cd6ed661c59295cb65348a126fb245757d4Michael Kolb * Licensed under the Apache License, Version 2.0 (the "License");
525668cd6ed661c59295cb65348a126fb245757d4Michael Kolb * you may not use this file except in compliance with the License.
625668cd6ed661c59295cb65348a126fb245757d4Michael Kolb * You may obtain a copy of the License at
725668cd6ed661c59295cb65348a126fb245757d4Michael Kolb *
825668cd6ed661c59295cb65348a126fb245757d4Michael Kolb *      http://www.apache.org/licenses/LICENSE-2.0
925668cd6ed661c59295cb65348a126fb245757d4Michael Kolb *
1025668cd6ed661c59295cb65348a126fb245757d4Michael Kolb * Unless required by applicable law or agreed to in writing, software
1125668cd6ed661c59295cb65348a126fb245757d4Michael Kolb * distributed under the License is distributed on an "AS IS" BASIS,
1225668cd6ed661c59295cb65348a126fb245757d4Michael Kolb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1325668cd6ed661c59295cb65348a126fb245757d4Michael Kolb * See the License for the specific language governing permissions and
1425668cd6ed661c59295cb65348a126fb245757d4Michael Kolb * limitations under the License.
1525668cd6ed661c59295cb65348a126fb245757d4Michael Kolb */
1625668cd6ed661c59295cb65348a126fb245757d4Michael Kolb
1725668cd6ed661c59295cb65348a126fb245757d4Michael Kolbpackage com.android.camera.ui;
1825668cd6ed661c59295cb65348a126fb245757d4Michael Kolb
1925668cd6ed661c59295cb65348a126fb245757d4Michael Kolbimport android.app.Activity;
2025668cd6ed661c59295cb65348a126fb245757d4Michael Kolbimport android.os.Handler;
2125668cd6ed661c59295cb65348a126fb245757d4Michael Kolbimport android.view.LayoutInflater;
2225668cd6ed661c59295cb65348a126fb245757d4Michael Kolbimport android.view.View;
2325668cd6ed661c59295cb65348a126fb245757d4Michael Kolbimport android.view.ViewGroup;
2425668cd6ed661c59295cb65348a126fb245757d4Michael Kolbimport android.widget.TextView;
2525668cd6ed661c59295cb65348a126fb245757d4Michael Kolb
2625668cd6ed661c59295cb65348a126fb245757d4Michael Kolbimport com.android.camera.Util;
27a3dc2c0dd75f4659146fcd257ce32acc3800ae5fJohn Reckimport com.android.gallery3d.R;
2825668cd6ed661c59295cb65348a126fb245757d4Michael Kolb
2925668cd6ed661c59295cb65348a126fb245757d4Michael Kolbpublic class RotateTextToast {
3025668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    private static final int TOAST_DURATION = 5000; // milliseconds
3125668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    ViewGroup mLayoutRoot;
3225668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    RotateLayout mToast;
3325668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    Handler mHandler;
3425668cd6ed661c59295cb65348a126fb245757d4Michael Kolb
3525668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    public RotateTextToast(Activity activity, int textResourceId, int orientation) {
3625668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        mLayoutRoot = (ViewGroup) activity.getWindow().getDecorView();
3725668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        LayoutInflater inflater = activity.getLayoutInflater();
3825668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        View v = inflater.inflate(R.layout.rotate_text_toast, mLayoutRoot);
3925668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        mToast = (RotateLayout) v.findViewById(R.id.rotate_toast);
4025668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        TextView tv = (TextView) mToast.findViewById(R.id.message);
4125668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        tv.setText(textResourceId);
4225668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        mToast.setOrientation(orientation, false);
4325668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        mHandler = new Handler();
4425668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    }
4525668cd6ed661c59295cb65348a126fb245757d4Michael Kolb
4625668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    private final Runnable mRunnable = new Runnable() {
4725668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        @Override
4825668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        public void run() {
4925668cd6ed661c59295cb65348a126fb245757d4Michael Kolb            Util.fadeOut(mToast);
5025668cd6ed661c59295cb65348a126fb245757d4Michael Kolb            mLayoutRoot.removeView(mToast);
5125668cd6ed661c59295cb65348a126fb245757d4Michael Kolb            mToast = null;
5225668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        }
5325668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    };
5425668cd6ed661c59295cb65348a126fb245757d4Michael Kolb
5525668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    public void show() {
5625668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        mToast.setVisibility(View.VISIBLE);
5725668cd6ed661c59295cb65348a126fb245757d4Michael Kolb        mHandler.postDelayed(mRunnable, TOAST_DURATION);
5825668cd6ed661c59295cb65348a126fb245757d4Michael Kolb    }
5925668cd6ed661c59295cb65348a126fb245757d4Michael Kolb}
60