android tv activity,TvSettingsActivity.java

/*

* Copyright (C) 2016 The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License

*/

package com.android.tv.settings;

import android.app.Activity;

import android.app.Fragment;

import android.os.Bundle;

import android.support.annotation.Nullable;

import android.transition.Scene;

import android.transition.Slide;

import android.transition.Transition;

import android.transition.TransitionManager;

import android.view.Gravity;

import android.view.ViewGroup;

import android.view.ViewTreeObserver;

public abstract class TvSettingsActivity extends Activity {

private static final String SETTINGS_FRAGMENT_TAG =

"com.android.tv.settings.MainSettings.SETTINGS_FRAGMENT";

@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

if (savedInstanceState == null) {

final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);

root.getViewTreeObserver().addOnPreDrawListener(

new ViewTreeObserver.OnPreDrawListener() {

@Override

public boolean onPreDraw() {

root.getViewTreeObserver().removeOnPreDrawListener(this);

final Scene scene = new Scene(root);

scene.setEnterAction(new Runnable() {

@Override

public void run() {

final Fragment fragment = createSettingsFragment();

if (fragment != null) {

getFragmentManager().beginTransaction()

.add(android.R.id.content, fragment,

SETTINGS_FRAGMENT_TAG)

.commitNow();

}

}

});

final Slide slide = new Slide(Gravity.END);

slide.setSlideFraction(

getResources().getDimension(R.dimen.lb_settings_pane_width)

/ root.getWidth());

TransitionManager.go(scene, slide);

// Skip the current draw, there's nothing in it

return false;

}

});

}

}

@Override

public void finish() {

final Fragment fragment = getFragmentManager().findFragmentByTag(SETTINGS_FRAGMENT_TAG);

if (isResumed() && fragment != null) {

final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);

final Scene scene = new Scene(root);

scene.setEnterAction(new Runnable() {

@Override

public void run() {

getFragmentManager().beginTransaction()

.remove(fragment)

.commitNow();

}

});

final Slide slide = new Slide(Gravity.END);

slide.setSlideFraction(

getResources().getDimension(R.dimen.lb_settings_pane_width) / root.getWidth());

slide.addListener(new Transition.TransitionListener() {

@Override

public void onTransitionStart(Transition transition) {

getWindow().setDimAmount(0);

}

@Override

public void onTransitionEnd(Transition transition) {

transition.removeListener(this);

TvSettingsActivity.super.finish();

}

@Override

public void onTransitionCancel(Transition transition) {

}

@Override

public void onTransitionPause(Transition transition) {

}

@Override

public void onTransitionResume(Transition transition) {

}

});

TransitionManager.go(scene, slide);

} else {

super.finish();

}

}

protected abstract Fragment createSettingsFragment();

}

Java程序

|

123行

|

4.76 KB

/*

* Copyright (C) 2016 The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License

*/

package com.android.tv.settings;

import android.app.Activity;

import android.app.Fragment;

import android.os.Bundle;

import android.support.annotation.Nullable;

import android.transition.Scene;

import android.transition.Slide;

import android.transition.Transition;

import android.transition.TransitionManager;

import android.view.Gravity;

import android.view.ViewGroup;

import android.view.ViewTreeObserver;

public abstract class TvSettingsActivity extends Activity {

private static final String SETTINGS_FRAGMENT_TAG =

"com.android.tv.settings.MainSettings.SETTINGS_FRAGMENT";

@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

if (savedInstanceState == null) {

final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);

root.getViewTreeObserver().addOnPreDrawListener(

new ViewTreeObserver.OnPreDrawListener() {

@Override

public boolean onPreDraw() {

root.getViewTreeObserver().removeOnPreDrawListener(this);

final Scene scene = new Scene(root);

scene.setEnterAction(new Runnable() {

@Override

public void run() {

final Fragment fragment = createSettingsFragment();

if (fragment != null) {

getFragmentManager().beginTransaction()

.add(android.R.id.content, fragment,

SETTINGS_FRAGMENT_TAG)

.commitNow();

}

}

});

final Slide slide = new Slide(Gravity.END);

slide.setSlideFraction(

getResources().getDimension(R.dimen.lb_settings_pane_width)

/ root.getWidth());

TransitionManager.go(scene, slide);

// Skip the current draw, there's nothing in it

return false;

}

});

}

}

@Override

public void finish() {

final Fragment fragment = getFragmentManager().findFragmentByTag(SETTINGS_FRAGMENT_TAG);

if (isResumed() && fragment != null) {

final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);

final Scene scene = new Scene(root);

scene.setEnterAction(new Runnable() {

@Override

public void run() {

getFragmentManager().beginTransaction()

.remove(fragment)

.commitNow();

}

});

final Slide slide = new Slide(Gravity.END);

slide.setSlideFraction(

getResources().getDimension(R.dimen.lb_settings_pane_width) / root.getWidth());

slide.addListener(new Transition.TransitionListener() {

@Override

public void onTransitionStart(Transition transition) {

getWindow().setDimAmount(0);

}

@Override

public void onTransitionEnd(Transition transition) {

transition.removeListener(this);

TvSettingsActivity.super.finish();

}

@Override

public void onTransitionCancel(Transition transition) {

}

@Override

public void onTransitionPause(Transition transition) {

}

@Override

public void onTransitionResume(Transition transition) {

}

});

TransitionManager.go(scene, slide);

} else {

super.finish();

}

}

protected abstract Fragment createSettingsFragment();

}

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.a2, PID: 18827 android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.a2/com.example.a2.jisuanqi}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2049) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1709) at android.app.Activity.startActivityForResult(Activity.java:5192) at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597) at android.app.Activity.startActivityForResult(Activity.java:5150) at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583) at android.app.Activity.startActivity(Activity.java:5521) at android.app.Activity.startActivity(Activity.java:5489) at com.example.a2.MainActivity$1.onClick(MainActivity.java:37) at android.view.View.performClick(View.java:7125) at android.view.View.performClickInternal(View.java:7102) at android.view.View.access$3500(View.java:801) at android.view.View$PerformClick.run(View.java:27336) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
最新发布
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值