├── 1.png ├── Android-Scrap ├── .gitignore ├── android-scrap │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ ├── project.properties │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── org │ │ │ └── heaven7 │ │ │ └── scrap │ │ │ ├── core │ │ │ ├── ContainerActivity.java │ │ │ ├── ScrapConstant.java │ │ │ ├── anim │ │ │ │ ├── AnimateExecutor.java │ │ │ │ ├── InternalAnimationListener.java │ │ │ │ ├── InternalAnimatorListener.java │ │ │ │ └── TransitionAnimateExecutor.java │ │ │ ├── delegate │ │ │ │ ├── AbstractUiDelegate.java │ │ │ │ ├── ListRequestUiDelegate.java │ │ │ │ ├── RequestUiDelegate.java │ │ │ │ ├── SingleActivityUiDelegate.java │ │ │ │ └── StyledUiDelegate.java │ │ │ ├── event │ │ │ │ ├── ActivityEventAdapter.java │ │ │ │ ├── ActivityEventCallbackGroup.java │ │ │ │ └── IActivityEventCallback.java │ │ │ ├── lifecycle │ │ │ │ ├── ActivityLifeCycleAdapter.java │ │ │ │ ├── ActivityLifeCycleDispatcher.java │ │ │ │ └── IActivityLifeCycleCallback.java │ │ │ └── oneac │ │ │ │ ├── ActivityController.java │ │ │ │ ├── ActivityViewController.java │ │ │ │ ├── BaseScrapView.java │ │ │ │ ├── CacheHelper.java │ │ │ │ ├── ExpandArrayList.java │ │ │ │ ├── IBackEventProcessor.java │ │ │ │ ├── IntentExecutor.java │ │ │ │ ├── LoadingParam.java │ │ │ │ ├── ScrapHelper.java │ │ │ │ ├── StackMode.java │ │ │ │ └── Transaction.java │ │ │ └── util │ │ │ ├── ArrayList2.java │ │ │ ├── SpringUtil.java │ │ │ └── Utils.java │ │ └── res │ │ ├── layout │ │ ├── lib_style_ac_container.xml │ │ ├── lib_style_ac_no_overlap.xml │ │ └── lib_style_ac_overlap.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── dimens.xml │ │ ├── ids.xml │ │ ├── strings.xml │ │ └── styles.xml ├── backup │ ├── ResourceHoldable.java │ └── ResourceHolder.java ├── bintrayUpload_backup.txt ├── build.gradle ├── common.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib.gradle ├── lib_sample │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── heaven7 │ │ │ └── android │ │ │ └── style │ │ │ └── libsample │ │ │ ├── OnClickSampleItemListener.java │ │ │ ├── SampleConstants.java │ │ │ ├── module │ │ │ └── SampleItem.java │ │ │ └── scrap │ │ │ └── ListScrapView.java │ │ └── res │ │ ├── layout │ │ ├── lib_sample_item_button.xml │ │ └── lib_sample_list.xml │ │ └── values │ │ └── strings.xml ├── samples │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── org │ │ │ └── heaven7 │ │ │ └── scrap │ │ │ └── sample │ │ │ ├── MainScrapView.java │ │ │ ├── ScrapApp.java │ │ │ ├── ScrapLog.java │ │ │ ├── scrapview │ │ │ ├── CommonView.java │ │ │ ├── EntryScrapView.java │ │ │ ├── ScrapView.java │ │ │ ├── TestKeyEventScrapView.java │ │ │ ├── TestLifeCycleScrapView.java │ │ │ ├── TestTransitionScrapView_enter.java │ │ │ ├── TestTransitionScrapView_exit.java │ │ │ └── TestVisivilityScrapView.java │ │ │ └── util │ │ │ └── DialogUtil.java │ │ └── res │ │ ├── drawable-hdpi │ │ └── ic_back.png │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── feature.xml │ │ ├── item_demo.xml │ │ ├── item_girl.xml │ │ ├── scrap_main.xml │ │ ├── scrap_middle_common.xml │ │ ├── scrap_middle_test_visibile.xml │ │ ├── scrap_test_transition_enter.xml │ │ └── scrap_test_transition_exit.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── raw │ │ ├── scrap_config.properties │ │ └── scrap_data_binding_demo.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml └── settings.gradle ├── LICENSE ├── README.md └── release-notes.md /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/1.png -------------------------------------------------------------------------------- /Android-Scrap/.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # Android Studio 23 | .idea/ 24 | .gradle 25 | /*/local.properties 26 | /*/out 27 | build 28 | /*/*/production 29 | *.iml 30 | *.iws 31 | *.ipr 32 | *~ 33 | *.swp 34 | 35 | scrap_library 36 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply from: '../lib.gradle' 3 | apply plugin: 'com.github.dcendents.android-maven' 4 | 5 | group='com.github.LightSun' 6 | 7 | // default have 8 | android { 9 | compileSdkVersion rootProject.ext.compileSdkVersion 10 | buildToolsVersion rootProject.ext.buildToolsVersion 11 | 12 | defaultConfig { 13 | //applicationId "org.heaven7.scrap" 14 | minSdkVersion rootProject.ext.minSdkVersion 15 | targetSdkVersion rootProject.ext.targetSdkVersion 16 | versionCode 3 17 | versionName "1.2" 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation fileTree(dir: 'libs', include: ['*.jar']) 33 | //implementation 'com.android.support:appcompat-v7:28.0.0' 34 | implementation "androidx.appcompat:appcompat:1.1.0" 35 | } 36 | 37 | //apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle" 38 | 39 | tasks.withType(JavaCompile) { 40 | options.encoding = "UTF-8" 41 | } 42 | 43 | task sourcesJar(type: Jar) { 44 | from android.sourceSets.main.java.srcDirs 45 | getArchiveClassifier().set('sources') 46 | //classifier = 'sources' 47 | } 48 | 49 | task javadoc(type: Javadoc) { 50 | failOnError false 51 | source = android.sourceSets.main.java.sourceFiles 52 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 53 | classpath += configurations.compile 54 | } 55 | 56 | task javadocJar(type: Jar, dependsOn: javadoc) { 57 | //classifier = 'javadoc' 58 | getArchiveClassifier().set('javadoc') 59 | from javadoc.destinationDir 60 | } 61 | 62 | artifacts { 63 | archives sourcesJar 64 | archives javadocJar 65 | } -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in I:\android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/project.properties: -------------------------------------------------------------------------------- 1 | #project 2 | project.name = android-scrap 3 | project.groupId = org.heaven7.scrap 4 | project.artifactId = android-scrap 5 | project.packaging = aar 6 | project.siteUrl = https://github.com/LightSun/android-scrap 7 | project.gitUrl = https://github.com/LightSun/android-scrap.git 8 | 9 | #javadoc 10 | javadoc.name=android-scrap 11 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/ContainerActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core; 18 | 19 | import android.app.Activity; 20 | import android.content.Intent; 21 | import android.content.pm.ActivityInfo; 22 | import android.content.res.Configuration; 23 | import android.content.res.TypedArray; 24 | import android.os.Build; 25 | import android.os.Bundle; 26 | import android.view.KeyEvent; 27 | import android.view.MotionEvent; 28 | 29 | import androidx.annotation.NonNull; 30 | import androidx.appcompat.app.AppCompatActivity; 31 | import androidx.fragment.app.Fragment; 32 | import androidx.fragment.app.FragmentTransaction; 33 | 34 | import org.heaven7.scrap.core.delegate.AbstractUiDelegate; 35 | import org.heaven7.scrap.core.delegate.SingleActivityUiDelegate; 36 | import org.heaven7.scrap.core.event.ActivityEventCallbackGroup; 37 | 38 | import java.lang.reflect.Field; 39 | import java.lang.reflect.Method; 40 | import java.util.List; 41 | 42 | /** 43 | * the container activity. 44 | * 45 | * @author heaven7 46 | */ 47 | public class ContainerActivity extends AppCompatActivity { 48 | 49 | private AbstractUiDelegate mDelegate; 50 | 51 | @Override 52 | protected void onCreate(Bundle savedInstanceState) { 53 | /* 54 | * 修复部分 Android 8.0 手机在TargetSDK 大于 26 时,在透明主题时指定 Activity 方向时崩溃的问题 55 | */ 56 | if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) { 57 | fixOrientation(); 58 | } 59 | super.onCreate(savedInstanceState); 60 | 61 | String cn = getIntent().getStringExtra(ScrapConstant.KEY_UI_DELEGATE); 62 | if(cn == null){ 63 | mDelegate = new SingleActivityUiDelegate(); 64 | }else { 65 | try { 66 | mDelegate = (AbstractUiDelegate) Class.forName(cn).newInstance(); 67 | } catch (Exception e) { 68 | throw new RuntimeException(e); 69 | } 70 | } 71 | mDelegate.setActivity(this); 72 | mDelegate.onPreSetContentView(); 73 | mDelegate.clearAllFragments(); 74 | setContentView(mDelegate.getLayoutId()); 75 | mDelegate.setStatusBar(); 76 | 77 | //on initialize 78 | mDelegate.onInitialize(getIntent(), savedInstanceState); 79 | //on-create 80 | mDelegate.getLifeCycleDispatcher().dispatchActivityOnCreate(this, savedInstanceState); 81 | } 82 | private boolean fixOrientation() { 83 | try { 84 | Field field = Activity.class.getDeclaredField("mActivityInfo"); 85 | field.setAccessible(true); 86 | ActivityInfo o = (ActivityInfo) field.get(this); 87 | o.screenOrientation = -1; 88 | field.setAccessible(false); 89 | return true; 90 | } catch (Exception e) { 91 | e.printStackTrace(); 92 | } 93 | return false; 94 | } 95 | /** 96 | * 清除所有已存在的 Fragment 防止因重建 Activity 时,前 Fragment 没有销毁和重新复用导致界面重复显示 97 | * 如果有自己实现 Fragment 的复用,请复写此方法并不实现内容 98 | */ 99 | protected void clearAllFragmentExistBeforeCreate() { 100 | List fragments = getSupportFragmentManager().getFragments(); 101 | if (fragments.size() == 0) return; 102 | 103 | FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); 104 | for (Fragment fragment : fragments) { 105 | fragmentTransaction.remove(fragment); 106 | } 107 | fragmentTransaction.commitNow(); 108 | } 109 | /** 110 | * 判断当前主题是否是透明悬浮 111 | */ 112 | private boolean isTranslucentOrFloating() { 113 | boolean isTranslucentOrFloating = false; 114 | try { 115 | int[] styleableRes = (int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null); 116 | final TypedArray ta = obtainStyledAttributes(styleableRes); 117 | Method m = ActivityInfo.class.getMethod("isTranslucentOrFloating", TypedArray.class); 118 | m.setAccessible(true); 119 | isTranslucentOrFloating = (boolean) m.invoke(null, ta); 120 | m.setAccessible(false); 121 | } catch (Exception e) { 122 | e.printStackTrace(); 123 | } 124 | return isTranslucentOrFloating; 125 | } 126 | 127 | @Override 128 | protected void onNewIntent(Intent intent) { 129 | super.onNewIntent(intent); 130 | setIntent(intent); 131 | mDelegate.onInitialize(getIntent(), null); 132 | } 133 | 134 | @Override 135 | public void onWindowFocusChanged(boolean hasFocus) { 136 | super.onWindowFocusChanged(hasFocus); 137 | 138 | mDelegate.getLifeCycleDispatcher() 139 | .dispatchActivityOnWindowFocusChanged(this, hasFocus); 140 | } 141 | 142 | @Override 143 | protected void onPostCreate(Bundle savedInstanceState) { 144 | super.onPostCreate(savedInstanceState); 145 | mDelegate.getLifeCycleDispatcher() 146 | .dispatchActivityOnPostCreate(this, savedInstanceState); 147 | } 148 | 149 | @Override 150 | protected void onStart() { 151 | super.onStart(); 152 | mDelegate.getLifeCycleDispatcher() 153 | .dispatchActivityOnStart(this); 154 | } 155 | 156 | @Override 157 | protected void onResume() { 158 | super.onResume(); 159 | mDelegate.getLifeCycleDispatcher() 160 | .dispatchActivityOnResume(this); 161 | } 162 | 163 | @Override 164 | protected void onPause() { 165 | super.onPause(); 166 | mDelegate.getLifeCycleDispatcher() 167 | .dispatchActivityOnPause(this); 168 | } 169 | 170 | @Override 171 | protected void onStop() { 172 | super.onStop(); 173 | mDelegate.getLifeCycleDispatcher() 174 | .dispatchActivityOnStop(this); 175 | } 176 | 177 | @Override 178 | protected void onDestroy() { 179 | super.onDestroy(); 180 | mDelegate.onDestroy(); 181 | mDelegate.getLifeCycleDispatcher().dispatchActivityOnDestroy(this); 182 | } 183 | 184 | @Override 185 | public void onConfigurationChanged(Configuration newConfig) { 186 | super.onConfigurationChanged(newConfig); 187 | mDelegate.getLifeCycleDispatcher() 188 | .dispatchActivityOnConfigurationChanged(this, newConfig); 189 | } 190 | 191 | @Override 192 | protected void onSaveInstanceState(Bundle outState) { 193 | super.onSaveInstanceState(outState); 194 | mDelegate.onSaveInstanceState(outState); 195 | } 196 | 197 | @Override 198 | protected void onRestoreInstanceState(Bundle savedInstanceState) { 199 | super.onRestoreInstanceState(savedInstanceState); 200 | mDelegate.onRestoreInstanceState(savedInstanceState); 201 | } 202 | 203 | @Override 204 | protected void onUserLeaveHint() { 205 | super.onUserLeaveHint(); 206 | mDelegate.getLifeCycleDispatcher() 207 | .dispatchActivityOnUserLeaveHint(this); 208 | } 209 | 210 | @Override 211 | public void onLowMemory() { 212 | super.onLowMemory(); 213 | mDelegate.getLifeCycleDispatcher() 214 | .dispatchActivityOnLowMemory(this); 215 | } 216 | 217 | @Override 218 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 219 | super.onActivityResult(requestCode, resultCode, data); 220 | mDelegate.getLifeCycleDispatcher() 221 | .dispatchActivityOnActivityResult(this, requestCode, resultCode, data); 222 | } 223 | 224 | @Override 225 | public boolean onKeyDown(int keyCode, KeyEvent event) { 226 | ActivityEventCallbackGroup dispatcher = mDelegate.getEventGroup(); 227 | if (dispatcher.onKeyDown(keyCode, event)) { 228 | return true; 229 | } 230 | return super.onKeyDown(keyCode, event); 231 | } 232 | 233 | @Override 234 | public boolean onKeyUp(int keyCode, KeyEvent event) { 235 | ActivityEventCallbackGroup dispatcher = mDelegate.getEventGroup(); 236 | if (dispatcher.onKeyUp(keyCode, event)) { 237 | return true; 238 | } 239 | return super.onKeyUp(keyCode, event); 240 | } 241 | 242 | @Override 243 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { 244 | ActivityEventCallbackGroup dispatcher = mDelegate.getEventGroup(); 245 | if (dispatcher.onKeyShortcut(keyCode, event)) { 246 | return true; 247 | } 248 | return super.onKeyShortcut(keyCode, event); 249 | } 250 | 251 | @Override 252 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { 253 | ActivityEventCallbackGroup dispatcher = mDelegate.getEventGroup(); 254 | if (dispatcher.onKeyLongPress(keyCode, event)) { 255 | return true; 256 | } 257 | return super.onKeyLongPress(keyCode, event); 258 | } 259 | 260 | @Override 261 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { 262 | ActivityEventCallbackGroup dispatcher = mDelegate.getEventGroup(); 263 | if (dispatcher.onKeyMultiple(keyCode, event)) { 264 | return true; 265 | } 266 | return super.onKeyMultiple(keyCode, repeatCount, event); 267 | } 268 | 269 | @Override 270 | public void onBackPressed() { 271 | if(mDelegate.onBackPressed()){ 272 | return; 273 | } 274 | ActivityEventCallbackGroup dispatcher = mDelegate.getEventGroup(); 275 | if (dispatcher.onBackPressed()) { 276 | return; 277 | } 278 | super.onBackPressed(); 279 | } 280 | 281 | @Override 282 | public boolean onTouchEvent(MotionEvent event) { 283 | ActivityEventCallbackGroup dispatcher = mDelegate.getEventGroup(); 284 | if (dispatcher.onTouchEvent(event)) { 285 | return true; 286 | } 287 | return super.onTouchEvent(event); 288 | } 289 | 290 | @Override 291 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 292 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 293 | mDelegate.getLifeCycleDispatcher().dispatchActivityOnActivityPermissionResult(this, 294 | requestCode, permissions, grantResults); 295 | } 296 | 297 | @Override 298 | public void finish() { 299 | super.finish(); 300 | mDelegate.onFinish(); 301 | } 302 | } 303 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/ScrapConstant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core; 18 | /** 19 | * Created by heaven7 on 2015/8/8. 20 | */ 21 | public interface ScrapConstant { 22 | 23 | String CONFIG_FILENAME = "scrap_config"; 24 | String CONFIG_KEY_MAIN_SCRAP_VIEW = "scrap_view_main"; 25 | String CONFIG_KEY_MAIN_SCRAP_VIEW_BACK_STACK = "scrap_view_main_addBackStack"; 26 | 27 | String KEY_UI_DELEGATE = "__UiDelegate"; 28 | String KEY_PARAMETER = "__param"; 29 | String KEY_OVERLAP = "__overlap"; 30 | } 31 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/anim/AnimateExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.anim; 18 | 19 | import android.animation.Animator; 20 | import android.annotation.TargetApi; 21 | import android.os.Build; 22 | import android.view.View; 23 | import android.view.ViewPropertyAnimator; 24 | import android.view.animation.Animation; 25 | 26 | import com.heaven7.java.base.anno.CalledInternal; 27 | 28 | import org.heaven7.scrap.core.oneac.BaseScrapView; 29 | 30 | /** 31 | * used to perform the animation of cross the stage(eg: from one abstract view to another). but i don't know which you want to use. 32 | * such as: Animation , Animator , ViewPropertyAnimator. 33 | * 34 | * @author heaven7 35 | * @see #TYPE_ANIMATOR 36 | * @see #TYPE_ANIMATION 37 | * @see #TYPE_VIEW_PROPERTY_ANIMATOR 38 | */ 39 | public abstract class AnimateExecutor { 40 | 41 | public static final byte TYPE_ANIMATOR = 1; 42 | public static final byte TYPE_ANIMATION = 2; 43 | public static final byte TYPE_VIEW_PROPERTY_ANIMATOR = 3; 44 | 45 | /** 46 | * @return a AnimateCategoryType , can be null.if you don't need animation 47 | * @see #prepareAnimation(View, boolean, BaseScrapView, BaseScrapView) 48 | */ 49 | protected byte getType(boolean enter, BaseScrapView previous, 50 | BaseScrapView current){ 51 | return TYPE_ANIMATOR; 52 | } 53 | 54 | /** 55 | * prepare an Animation which will be start by framework. it will be start only if 56 | * {@link #getType(boolean, BaseScrapView, BaseScrapView)} return {@link #TYPE_ANIMATION} 57 | * 58 | * @param target the target to animate,often is the view of BaseScrapView 59 | * @param enter true means is the enter animation,false is the exit animation! 60 | * @param previous the previous BaseScrapView which will perform exit animation! 61 | * @param current the current BaseScrapView which will perform enter animation! 62 | * @return an prepared animation but not start.can be null.if you don't need this animation 63 | */ 64 | protected Animation prepareAnimation(View target, boolean enter, BaseScrapView previous, 65 | BaseScrapView current) { 66 | return null; 67 | } 68 | 69 | /** 70 | * same as {@link #prepareAnimation(View, boolean, BaseScrapView, BaseScrapView)} 71 | * 72 | * @return an prepared animator but not start.can be null.if you don't need this animation 73 | * @see #prepareAnimation(View, boolean, BaseScrapView, BaseScrapView) 74 | */ 75 | protected abstract Animator prepareAnimator(View target, boolean enter, BaseScrapView previous, 76 | BaseScrapView current); 77 | 78 | /** 79 | * same as {@link #prepareAnimation(View, boolean, BaseScrapView, BaseScrapView)} 80 | * 81 | * @return an prepared ViewPropertyAnimator but not start.can be null.if you don't need this animation 82 | * @see #prepareAnimation(View, boolean, BaseScrapView, BaseScrapView) 83 | */ 84 | protected ViewPropertyAnimator prepareViewPropertyAnimator(View target, boolean enter, 85 | BaseScrapView previous, BaseScrapView current) { 86 | return null; 87 | } 88 | 89 | /*** 90 | * perform the concrete animation/animator/ViewPropertyAnimator when cross two 'BaseScrapView'. 91 | * the is called by the frame work! 92 | * @param target the target to animate,often is the view of BaseScrapView 93 | * @param enter true means is the enter animation,false is the exit animation! 94 | * @param previous the previous BaseScrapView which will perform exit animation! 95 | * @param current the current BaseScrapView which will perform enter animation! 96 | * @param l the animation end listener which must be called when animation is the end in exit animation. 97 | */ 98 | @CalledInternal 99 | @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) 100 | public void performAnimate(View target, boolean enter, BaseScrapView previous, 101 | BaseScrapView current, OnAnimateEndListener l) { 102 | 103 | byte type = getType(enter, previous, current); 104 | switch (type) { 105 | 106 | case TYPE_ANIMATION: 107 | Animation animation = prepareAnimation(target, enter, previous, current); 108 | if (animation != null) { 109 | if (animation.getRepeatCount() == Animation.INFINITE) { 110 | throw new IllegalStateException("In here Animation.getRepeatCount() can't be Animation.INFINITE!"); 111 | } 112 | if (l != null) 113 | animation.setAnimationListener(new InternalAnimationListener(target, l)); 114 | target.startAnimation(animation); 115 | } else { 116 | if (l != null) 117 | l.onAnimateEnd(target); 118 | } 119 | break; 120 | 121 | case TYPE_ANIMATOR: 122 | Animator animator = prepareAnimator(target, enter, previous, current); 123 | if (animator != null) { 124 | if (l != null) 125 | animator.addListener(new InternalAnimatorListener(target, l)); 126 | animator.start(); 127 | } else { 128 | if (l != null) 129 | l.onAnimateEnd(target); 130 | } 131 | break; 132 | 133 | case TYPE_VIEW_PROPERTY_ANIMATOR: 134 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { 135 | ViewPropertyAnimator propAnimator = prepareViewPropertyAnimator( 136 | target, enter, previous, current); 137 | if (propAnimator != null) { 138 | if (l != null) 139 | propAnimator.setListener(new InternalAnimatorListener(target, l)); 140 | propAnimator.start(); 141 | } else { 142 | if (l != null) 143 | l.onAnimateEnd(target); 144 | } 145 | } else { 146 | //unsupport not perform animate. call the end directly. 147 | if (l != null) 148 | l.onAnimateEnd(target); 149 | } 150 | break; 151 | 152 | default://such as null 153 | throw new UnsupportedOperationException("wrong animate type = " + type); 154 | } 155 | } 156 | 157 | /** 158 | * the animation end listener. 159 | * 160 | * @author heaven7 161 | */ 162 | public interface OnAnimateEndListener { 163 | /** 164 | * will be called at the end of animation. 165 | * 166 | * @param target the view to animate. 167 | */ 168 | void onAnimateEnd(View target); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/anim/InternalAnimationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.anim; 18 | 19 | import android.view.View; 20 | import android.view.animation.Animation; 21 | import android.view.animation.Animation.AnimationListener; 22 | 23 | 24 | /* package */ class InternalAnimationListener implements AnimationListener { 25 | 26 | final View target; 27 | final AnimateExecutor.OnAnimateEndListener l; 28 | 29 | public InternalAnimationListener(View target, AnimateExecutor.OnAnimateEndListener l) { 30 | super(); 31 | this.target = target; 32 | this.l = l; 33 | } 34 | 35 | @Override 36 | public void onAnimationStart(Animation animation) { 37 | } 38 | 39 | @Override 40 | public void onAnimationEnd(Animation animation) { 41 | l.onAnimateEnd(target); 42 | } 43 | 44 | @Override 45 | public void onAnimationRepeat(Animation animation) { 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/anim/InternalAnimatorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.anim; 18 | 19 | import android.animation.Animator; 20 | import android.animation.Animator.AnimatorListener; 21 | import android.view.View; 22 | /** 23 | * the internal anmator listener 24 | * @author heaven7 25 | */ 26 | /* package */ class InternalAnimatorListener implements AnimatorListener { 27 | 28 | final View target; 29 | final AnimateExecutor.OnAnimateEndListener l; 30 | 31 | public InternalAnimatorListener(View target, AnimateExecutor.OnAnimateEndListener l) { 32 | super(); 33 | this.target = target; 34 | this.l = l; 35 | } 36 | 37 | @Override 38 | public void onAnimationStart(Animator animation) { 39 | 40 | } 41 | 42 | @Override 43 | public void onAnimationEnd(Animator animation) { 44 | l.onAnimateEnd(target); 45 | } 46 | 47 | @Override 48 | public void onAnimationCancel(Animator animation) { 49 | 50 | } 51 | 52 | @Override 53 | public void onAnimationRepeat(Animator animation) { 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/anim/TransitionAnimateExecutor.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.anim; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.AnimatorSet; 6 | import android.animation.ObjectAnimator; 7 | import android.animation.ValueAnimator; 8 | import android.graphics.Bitmap; 9 | import android.graphics.Canvas; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.ImageView; 13 | 14 | import org.heaven7.scrap.core.oneac.BaseScrapView; 15 | import org.heaven7.scrap.util.SpringUtil; 16 | 17 | public class TransitionAnimateExecutor extends AnimateExecutor { 18 | 19 | private final int transitionId; 20 | 21 | public TransitionAnimateExecutor(int viewId) { 22 | this.transitionId = viewId; 23 | } 24 | 25 | @Override 26 | protected Animator prepareAnimator(View target, boolean enter, BaseScrapView previous, BaseScrapView current) { 27 | View lastView = previous.getView().findViewById(transitionId); 28 | View curView = current.getView().findViewById(transitionId); 29 | if(lastView == null || curView == null){ 30 | throw new IllegalStateException("for transition animation: you must assign a same view id."); 31 | } 32 | //translate, scale. then reset 33 | //prepare image view. 34 | final ImageView iv = new ImageView(target.getContext()); 35 | Bitmap bitmap = Bitmap.createBitmap(lastView.getWidth(), lastView.getHeight(), Bitmap.Config.RGB_565); 36 | Canvas canvas = new Canvas(bitmap); 37 | lastView.draw(canvas); 38 | iv.setImageBitmap(bitmap); 39 | 40 | final ViewGroup vg = (ViewGroup) previous.getView().getParent(); 41 | int[] pArr = new int[2]; 42 | vg.getLocationOnScreen(pArr); 43 | int[] arr = new int[2]; 44 | lastView.getLocationOnScreen(arr); 45 | int[] curArr = new int[2]; 46 | curView.getLocationOnScreen(curArr); 47 | 48 | ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams( 49 | ViewGroup.MarginLayoutParams.WRAP_CONTENT, 50 | ViewGroup.MarginLayoutParams.WRAP_CONTENT); 51 | //lp.leftMargin = arr[0] - pArr[0]; 52 | // lp.topMargin = arr[1] - pArr[1]; 53 | iv.setX(arr[0] - pArr[0]); 54 | iv.setY(arr[1] - pArr[1]); 55 | vg.addView(iv, lp); 56 | 57 | previous.getView().setVisibility(View.INVISIBLE); 58 | iv.setPivotX(lastView.getWidth()*1f / 2); 59 | iv.setPivotY(lastView.getHeight()*1f / 2); 60 | float targetSX = curView.getWidth() * 1f / lastView.getWidth(); 61 | float targetSY = curView.getHeight() * 1f / lastView.getHeight(); 62 | 63 | ObjectAnimator sx = ObjectAnimator.ofFloat(iv, View.SCALE_X, 1f, targetSX); 64 | ObjectAnimator sy = ObjectAnimator.ofFloat(iv, View.SCALE_Y, 1f, targetSY); 65 | //todo 66 | ObjectAnimator tx = ObjectAnimator.ofFloat(iv, View.X, 67 | (arr[0] - pArr[0]), 68 | curArr[0] - pArr[0] 69 | ); 70 | ObjectAnimator ty = ObjectAnimator.ofFloat(iv, View.Y, 71 | arr[1] - pArr[1], 72 | curArr[1] - pArr[1] 73 | ); 74 | tx.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 75 | @Override 76 | public void onAnimationUpdate(ValueAnimator animation) { 77 | Object val = animation.getAnimatedValue(); 78 | } 79 | }); 80 | 81 | AnimatorSet set = new AnimatorSet(); 82 | set.setDuration(2000); 83 | set.playTogether(sx, sy, tx, ty); 84 | set.addListener(new AnimatorListenerAdapter() { 85 | @Override 86 | public void onAnimationEnd(Animator animation) { 87 | previous.getView().setVisibility(View.VISIBLE); 88 | vg.removeView(iv); 89 | } 90 | }); 91 | return set; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/delegate/AbstractUiDelegate.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.delegate; 2 | 3 | 4 | import android.content.Intent; 5 | import android.content.res.Resources; 6 | import android.graphics.Color; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.widget.LinearLayout; 10 | 11 | import androidx.annotation.CallSuper; 12 | import androidx.annotation.IdRes; 13 | import androidx.fragment.app.Fragment; 14 | import androidx.fragment.app.FragmentActivity; 15 | import androidx.fragment.app.FragmentTransaction; 16 | 17 | import com.heaven7.core.util.AppUtils; 18 | 19 | import org.heaven7.scrap.core.ScrapConstant; 20 | import org.heaven7.scrap.core.event.ActivityEventCallbackGroup; 21 | import org.heaven7.scrap.core.lifecycle.ActivityLifeCycleDispatcher; 22 | import org.heaven7.scrap.util.Utils; 23 | 24 | import java.util.List; 25 | 26 | public abstract class AbstractUiDelegate { 27 | 28 | private FragmentActivity activity; 29 | private Object parameter; 30 | 31 | private ActivityLifeCycleDispatcher mLifecycleDispatcher; 32 | private ActivityEventCallbackGroup mEventGroup; 33 | 34 | public FragmentActivity getActivity() { 35 | return activity; 36 | } 37 | public void setActivity(FragmentActivity activity) { 38 | this.activity = activity; 39 | } 40 | public T findViewById(@IdRes int id){ 41 | return activity.findViewById(id); 42 | } 43 | public Resources getResources(){ 44 | return activity.getResources(); 45 | } 46 | @SuppressWarnings("unchecked") 47 | public T getParameter(){ 48 | return (T) parameter; 49 | } 50 | 51 | public ActivityLifeCycleDispatcher getLifeCycleDispatcher(){ 52 | if(mLifecycleDispatcher == null){ 53 | mLifecycleDispatcher = new ActivityLifeCycleDispatcher(); 54 | } 55 | return mLifecycleDispatcher; 56 | } 57 | public ActivityEventCallbackGroup getEventGroup(){ 58 | if(mEventGroup == null){ 59 | mEventGroup = new ActivityEventCallbackGroup(); 60 | } 61 | return mEventGroup; 62 | } 63 | 64 | //-------------------------------------------- 65 | 66 | /** 67 | * called on pre setContentView 68 | */ 69 | public void onPreSetContentView() { 70 | } 71 | 72 | public abstract int getLayoutId(); 73 | 74 | @CallSuper 75 | public void onInitialize(Intent intent, Bundle savedInstanceState){ 76 | Bundle extras = intent.getExtras(); 77 | if(extras != null){ 78 | parameter = extras.get(ScrapConstant.KEY_PARAMETER); 79 | } 80 | } 81 | 82 | public boolean onBackPressed() { 83 | return false; 84 | } 85 | @CallSuper 86 | public void onFinish() { 87 | 88 | } 89 | @CallSuper 90 | public void onDestroy(){ 91 | 92 | } 93 | 94 | public void onSaveInstanceState(Bundle outState) { 95 | 96 | } 97 | public void onRestoreInstanceState(Bundle savedInstanceState) { 98 | 99 | } 100 | //------------------------------------ extra ------------------------------------------ 101 | /** 102 | * 清除所有已存在的 Fragment 防止因重建 Activity 时,前 Fragment 没有销毁和重新复用导致界面重复显示 103 | * 如果有自己实现 Fragment 的复用,请复写此方法并不实现内容 104 | */ 105 | public void clearAllFragments() { 106 | List fragments = getActivity().getSupportFragmentManager().getFragments(); 107 | if (fragments.size() == 0) return; 108 | 109 | FragmentTransaction transaction = getActivity() 110 | .getSupportFragmentManager() 111 | .beginTransaction(); 112 | for (Fragment fragment : fragments) { 113 | transaction.remove(fragment); 114 | } 115 | transaction.commitNow(); 116 | } 117 | 118 | /** 119 | * make action bar to fit system-bar height. 120 | * @param top the top view. often is the title-bar 121 | * @param fitSystemWindow true to fit system windows 122 | */ 123 | public void fitActionbarHeight(View top, boolean fitSystemWindow) { 124 | LinearLayout.MarginLayoutParams layoutParams = (LinearLayout.MarginLayoutParams) top.getLayoutParams(); 125 | layoutParams.topMargin = fitSystemWindow ? Utils.getSystemUIHeight(getActivity()) : 0; 126 | top.requestLayout(); 127 | } 128 | 129 | /** 130 | * set status bar 131 | */ 132 | public void setStatusBar() { 133 | FragmentActivity activity = getActivity(); 134 | AppUtils.fitStatusBarHeight(activity); 135 | AppUtils.setStatusBar(activity.getWindow(), getStatusBarColor()); 136 | } 137 | protected int getStatusBarColor() { 138 | return Color.LTGRAY; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/delegate/ListRequestUiDelegate.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.delegate; 2 | 3 | 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | 7 | import com.heaven7.android.component.network.NetworkContext; 8 | import com.heaven7.android.component.network.RequestConfig; 9 | import com.heaven7.android.component.network.list.ListHelper; 10 | import com.heaven7.android.pullrefresh.FooterDelegate; 11 | import com.heaven7.android.pullrefresh.PullToRefreshLayout; 12 | 13 | import org.heaven7.scrap.R; 14 | 15 | import java.util.Map; 16 | 17 | public abstract class ListRequestUiDelegate extends RequestUiDelegate implements ListHelper.Callback { 18 | 19 | private final ListHelper mListHelper; 20 | private PullToRefreshLayout mPullLayout; 21 | 22 | public ListRequestUiDelegate(NetworkContext context, ListHelper.Factory factory) { 23 | super(context); 24 | mListHelper = new ListHelper(context, factory, this); 25 | } 26 | 27 | public ListHelper getListHelper() { 28 | return mListHelper; 29 | } 30 | 31 | @Override 32 | public FooterDelegate getFooterDelegate() { 33 | return null; 34 | } 35 | @Override 36 | public PullToRefreshLayout getPullToRefreshLayout() { 37 | if(mPullLayout == null){ 38 | mPullLayout = findViewById(R.id.lib_style_pullToRefresh); 39 | } 40 | return mPullLayout; 41 | } 42 | @Override 43 | public void addRequestParams(Map params) { 44 | 45 | } 46 | @Override 47 | public void request(boolean refresh, RequestCallback callback) { 48 | throw new UnsupportedOperationException(); 49 | } 50 | 51 | public void request(boolean refresh){ 52 | mListHelper.requestData(refresh); 53 | } 54 | public void refresh(){ 55 | mListHelper.refresh(); 56 | } 57 | 58 | @Override 59 | public void onInitialize(Intent intent, Bundle savedInstanceState) { 60 | super.onInitialize(intent, savedInstanceState); 61 | mListHelper.onInitialize(getActivity(), savedInstanceState); 62 | 63 | refresh(); 64 | } 65 | 66 | @Override 67 | public abstract RequestConfig onCreateRequestConfig(); 68 | } 69 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/delegate/RequestUiDelegate.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.delegate; 2 | 3 | import com.heaven7.android.component.network.NetworkComponent; 4 | import com.heaven7.android.component.network.NetworkContext; 5 | 6 | 7 | public abstract class RequestUiDelegate extends StyledUiDelegate{ 8 | 9 | private final NetworkContext mNetworkContext; 10 | 11 | public RequestUiDelegate(NetworkContext mNetworkContext) { 12 | this.mNetworkContext = mNetworkContext; 13 | } 14 | 15 | public NetworkContext getNetworkContext() { 16 | return mNetworkContext; 17 | } 18 | 19 | public NetworkComponent getNetworkComponent() { 20 | return mNetworkContext.getNetworkComponent(); 21 | } 22 | 23 | @Override 24 | public void onDestroy() { 25 | NetworkComponent com = getNetworkComponent(); 26 | if(com != null){ 27 | com.cancelAll(); 28 | } 29 | super.onDestroy(); 30 | } 31 | 32 | public void request(RequestCallback callback){ 33 | request(false, callback); 34 | } 35 | 36 | public abstract void request(boolean refresh, RequestCallback callback); 37 | 38 | 39 | public interface RequestCallback{ 40 | 41 | default void onStart(){}; 42 | default void onEnd(){}; 43 | 44 | void onSuccess(T data); 45 | void onFailed(Throwable e); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/delegate/SingleActivityUiDelegate.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.delegate; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.widget.FrameLayout; 6 | 7 | import org.heaven7.scrap.R; 8 | import org.heaven7.scrap.core.event.ActivityEventCallbackGroup; 9 | import org.heaven7.scrap.core.lifecycle.ActivityLifeCycleDispatcher; 10 | import org.heaven7.scrap.core.oneac.ActivityController; 11 | 12 | public class SingleActivityUiDelegate extends AbstractUiDelegate { 13 | 14 | private static final String KEY_DATA = "__saud:data"; 15 | 16 | private FrameLayout mFl_content; 17 | 18 | @Override 19 | public int getLayoutId() { 20 | return R.layout.lib_style_ac_container; 21 | } 22 | 23 | @Override 24 | public ActivityEventCallbackGroup getEventGroup() { 25 | return ActivityController.get().getEventListenerGroup(); 26 | } 27 | @Override 28 | public ActivityLifeCycleDispatcher getLifeCycleDispatcher() { 29 | return ActivityController.get().getLifeCycleDispatcher(); 30 | } 31 | 32 | @Override 33 | public void onInitialize(Intent intent, Bundle savedInstanceState) { 34 | super.onInitialize(intent, savedInstanceState); 35 | init(savedInstanceState); 36 | } 37 | 38 | @Override 39 | public void onFinish() { 40 | super.onFinish(); 41 | ActivityController.get().attach(null, null,null); 42 | } 43 | 44 | private void init(Bundle savedInstanceState) { 45 | mFl_content = (FrameLayout) findViewById(R.id.lib_style_content); 46 | /* this must called after the container(top,middle,and bottom) is found ! */ 47 | ActivityController.get().attach(getActivity(), mFl_content, savedInstanceState); 48 | } 49 | 50 | @Override 51 | public void onSaveInstanceState(Bundle outState) { 52 | super.onSaveInstanceState(outState); 53 | Bundle b = new Bundle(); 54 | ActivityController.get().getViewController().onSaveInstanceState(b); 55 | outState.putBundle(KEY_DATA, b); 56 | } 57 | @Override 58 | public void onRestoreInstanceState(Bundle savedInstanceState) { 59 | super.onRestoreInstanceState(savedInstanceState); 60 | if(savedInstanceState != null){ 61 | Bundle b = savedInstanceState.getBundle(KEY_DATA); 62 | ActivityController.get().getViewController().onRestoreInstanceState(b); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/delegate/StyledUiDelegate.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.delegate; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.ViewGroup; 6 | 7 | import androidx.annotation.CallSuper; 8 | 9 | import org.heaven7.scrap.R; 10 | import org.heaven7.scrap.core.ScrapConstant; 11 | 12 | public abstract class StyledUiDelegate extends AbstractUiDelegate { 13 | 14 | private boolean mOverlapStyle; 15 | private ViewGroup mTopContainer; 16 | private ViewGroup mContentContainer; 17 | private ViewGroup mBottomContainer; 18 | 19 | public boolean isOverlapStyle() { 20 | return mOverlapStyle; 21 | } 22 | public ViewGroup getTopContainer() { 23 | return mTopContainer; 24 | } 25 | public ViewGroup getBottomContainer() { 26 | return mBottomContainer; 27 | } 28 | public ViewGroup getContentContainer() { 29 | return mContentContainer; 30 | } 31 | 32 | @Override 33 | public int getLayoutId() { 34 | return mOverlapStyle ? R.layout.lib_style_ac_overlap : R.layout.lib_style_ac_no_overlap; 35 | } 36 | @Override 37 | public void onInitialize(Intent intent, Bundle savedInstanceState) { 38 | super.onInitialize(intent, savedInstanceState); 39 | mTopContainer = findViewById(R.id.lib_style_top); 40 | mBottomContainer = findViewById(R.id.lib_style_bottom); 41 | mContentContainer = findViewById(R.id.lib_style_content); 42 | } 43 | 44 | @CallSuper 45 | @Override 46 | public void onPreSetContentView() { 47 | mOverlapStyle = getActivity().getIntent().getBooleanExtra(ScrapConstant.KEY_OVERLAP, false); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/event/ActivityEventAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.event; 18 | 19 | import android.view.KeyEvent; 20 | import android.view.MotionEvent; 21 | /** 22 | * the activity event adapter 23 | * @author heaven7 24 | * 25 | */ 26 | public abstract class ActivityEventAdapter implements IActivityEventCallback { 27 | 28 | @Override 29 | public boolean onKeyDown(int keyCode, KeyEvent event) { 30 | return false; 31 | } 32 | 33 | @Override 34 | public boolean onKeyUp(int keyCode, KeyEvent event) { 35 | return false; 36 | } 37 | 38 | @Override 39 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { 40 | return false; 41 | } 42 | 43 | @Override 44 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { 45 | return false; 46 | } 47 | 48 | @Override 49 | public boolean onKeyMultiple(int keyCode, KeyEvent event) { 50 | return false; 51 | } 52 | 53 | @Override 54 | public boolean onBackPressed() { 55 | return false; 56 | } 57 | 58 | @Override 59 | public boolean onTouchEvent(MotionEvent event) { 60 | return false; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/event/ActivityEventCallbackGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.event; 18 | 19 | import android.view.KeyEvent; 20 | import android.view.MotionEvent; 21 | 22 | import com.heaven7.java.base.anno.CalledInternal; 23 | 24 | import java.util.List; 25 | import java.util.concurrent.CopyOnWriteArrayList; 26 | 27 | /** 28 | * the group event callback of activity. 29 | * if one callback return true, the other callback after it will not receive the event. 30 | * 31 | * @author heaven7 32 | * @see ActivityEventCallbackGroup#registerActivityEventListener(IActivityEventCallback...) 33 | * @see #unregisterActivityEventListener(IActivityEventCallback...) 34 | */ 35 | public final class ActivityEventCallbackGroup implements IActivityEventCallback { 36 | 37 | private final List mListeners; 38 | private IActivityEventCallback mLastEventListener; 39 | 40 | public ActivityEventCallbackGroup() { 41 | mListeners = new CopyOnWriteArrayList(); 42 | } 43 | 44 | public void clear() { 45 | mListeners.clear(); 46 | } 47 | 48 | @CalledInternal 49 | public void setActivityLastEventListener(IActivityEventCallback l) { 50 | mLastEventListener = l; 51 | } 52 | 53 | /** 54 | * register a activity event listener. 55 | * 56 | * @param ls the listeners want to register. 57 | */ 58 | public void registerActivityEventListener(IActivityEventCallback... ls) { 59 | if (ls == null || ls.length == 0) 60 | return; 61 | final List mListeners = this.mListeners; 62 | for (int i = 0, size = ls.length; i < size; i++) { 63 | mListeners.add(ls[i]); 64 | } 65 | } 66 | 67 | /** 68 | * unregister a activity event listener. 69 | * 70 | * @param ls the listeners want to unregister. 71 | */ 72 | public void unregisterActivityEventListener(IActivityEventCallback... ls) { 73 | if (ls == null || ls.length == 0) 74 | return; 75 | final List mListeners = this.mListeners; 76 | for (IActivityEventCallback l : ls) { 77 | mListeners.remove(l); 78 | } 79 | } 80 | 81 | @Override 82 | public boolean onKeyDown(int keyCode, KeyEvent event) { 83 | final List mListeners = this.mListeners; 84 | for (int i = 0, size = mListeners.size(); i < size; i++) { 85 | if (mListeners.get(i).onKeyDown(keyCode, event)) { 86 | return true; 87 | } 88 | } 89 | if (mLastEventListener != null && mLastEventListener.onKeyDown(keyCode, event)) { 90 | return true; 91 | } 92 | return false; 93 | } 94 | 95 | @Override 96 | public boolean onKeyUp(int keyCode, KeyEvent event) { 97 | final List mListeners = this.mListeners; 98 | for (int i = 0, size = mListeners.size(); i < size; i++) { 99 | if (mListeners.get(i).onKeyUp(keyCode, event)) { 100 | return true; 101 | } 102 | } 103 | if (mLastEventListener != null && mLastEventListener.onKeyUp(keyCode, event)) { 104 | return true; 105 | } 106 | return false; 107 | } 108 | 109 | @Override 110 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { 111 | final List mListeners = this.mListeners; 112 | for (int i = 0, size = mListeners.size(); i < size; i++) { 113 | if (mListeners.get(i).onKeyShortcut(keyCode, event)) { 114 | return true; 115 | } 116 | } 117 | if (mLastEventListener != null && mLastEventListener.onKeyShortcut(keyCode, event)) { 118 | return true; 119 | } 120 | return false; 121 | } 122 | 123 | @Override 124 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { 125 | final List mListeners = this.mListeners; 126 | for (int i = 0, size = mListeners.size(); i < size; i++) { 127 | if (mListeners.get(i).onKeyLongPress(keyCode, event)) { 128 | return true; 129 | } 130 | } 131 | if (mLastEventListener != null && mLastEventListener.onKeyLongPress(keyCode, event)) { 132 | return true; 133 | } 134 | return false; 135 | } 136 | 137 | @Override 138 | public boolean onKeyMultiple(int keyCode, KeyEvent event) { 139 | final List mListeners = this.mListeners; 140 | for (int i = 0, size = mListeners.size(); i < size; i++) { 141 | if (mListeners.get(i).onKeyMultiple(keyCode, event)) { 142 | return true; 143 | } 144 | } 145 | if (mLastEventListener != null && mLastEventListener.onKeyMultiple(keyCode, event)) { 146 | return true; 147 | } 148 | return false; 149 | } 150 | 151 | @Override 152 | public boolean onBackPressed() { 153 | final List mListeners = this.mListeners; 154 | for (int i = 0, size = mListeners.size(); i < size; i++) { 155 | if (mListeners.get(i).onBackPressed()) { 156 | return true; 157 | } 158 | } 159 | if (mLastEventListener != null && mLastEventListener.onBackPressed()) { 160 | return true; 161 | } 162 | return false; 163 | } 164 | 165 | @Override 166 | public boolean onTouchEvent(MotionEvent event) { 167 | final List mListeners = this.mListeners; 168 | for (int i = 0, size = mListeners.size(); i < size; i++) { 169 | if (mListeners.get(i).onTouchEvent(event)) { 170 | return true; 171 | } 172 | } 173 | if (mLastEventListener != null && mLastEventListener.onTouchEvent(event)) { 174 | return true; 175 | } 176 | return false; 177 | } 178 | 179 | } 180 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/event/IActivityEventCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.event; 18 | 19 | import android.view.KeyEvent; 20 | import android.view.MotionEvent; 21 | /** 22 | * event listener: contains key event.and touchevent 23 | * this comes from Activity. the more you can see in Activity. 24 | * @author heaven7 25 | * 26 | */ 27 | public interface IActivityEventCallback { 28 | 29 | /** return true to prevent the event to continue spread */ 30 | boolean onKeyDown(int keyCode, KeyEvent event); 31 | 32 | /** return true to prevent the event to continue spread */ 33 | boolean onKeyUp(int keyCode, KeyEvent event); 34 | 35 | /** return true to prevent the event to continue spread */ 36 | boolean onKeyShortcut(int keyCode, KeyEvent event); 37 | 38 | /** return true to prevent the event to continue spread */ 39 | boolean onKeyLongPress(int keyCode, KeyEvent event); 40 | 41 | /** return true to prevent the event to continue spread */ 42 | boolean onKeyMultiple(int keyCode, KeyEvent event); 43 | 44 | /** return true to prevent the event to continue spread */ 45 | boolean onBackPressed(); 46 | 47 | /** return true to prevent the event to continue spread */ 48 | boolean onTouchEvent(MotionEvent event); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/lifecycle/ActivityLifeCycleAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.lifecycle; 18 | 19 | import android.app.Activity; 20 | import android.content.Intent; 21 | import android.content.res.Configuration; 22 | import android.os.Bundle; 23 | 24 | public class ActivityLifeCycleAdapter implements IActivityLifeCycleCallback { 25 | 26 | @Override 27 | public void onActivityCreate(Activity activity, Bundle savedInstanceState) { 28 | 29 | } 30 | 31 | @Override 32 | public void onActivityPostCreate(Activity activity, 33 | Bundle savedInstanceState) { 34 | 35 | } 36 | 37 | @Override 38 | public void onActivityStart(Activity activity) { 39 | 40 | } 41 | 42 | @Override 43 | public void onActivityResume(Activity activity) { 44 | 45 | } 46 | 47 | @Override 48 | public void onActivityPause(Activity activity) { 49 | 50 | } 51 | 52 | @Override 53 | public void onActivityStop(Activity activity) { 54 | 55 | } 56 | 57 | @Override 58 | public void onActivityDestroy(Activity activity) { 59 | 60 | } 61 | 62 | @Override 63 | public void onActivityConfigurationChanged(Activity activity, 64 | Configuration newConfig) { 65 | 66 | } 67 | 68 | @Override 69 | public void onActivityUserLeaveHint(Activity activity) { 70 | 71 | } 72 | 73 | @Override 74 | public void onActivityResult(Activity activity, int requestCode, 75 | int resultCode, Intent data) { 76 | 77 | } 78 | 79 | @Override 80 | public void onActivityLowMemory(Activity activity) { 81 | 82 | } 83 | 84 | @Override 85 | public void onActivityWindowFocusChanged(Activity activity, boolean hasFocus) { 86 | 87 | } 88 | 89 | @Override 90 | public void onRequestPermissionsResult(Activity activity, int requestCode, String[] permissions, int[] grantResult) { 91 | 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/lifecycle/ActivityLifeCycleDispatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.lifecycle; 18 | 19 | import android.app.Activity; 20 | import android.content.Intent; 21 | import android.content.res.Configuration; 22 | import android.os.Bundle; 23 | 24 | import androidx.annotation.NonNull; 25 | 26 | import com.heaven7.java.base.anno.CalledInternal; 27 | import com.heaven7.java.base.util.CopyOnWriteArray; 28 | 29 | public final class ActivityLifeCycleDispatcher { 30 | 31 | private final CopyOnWriteArray mCallbacks; 32 | 33 | public ActivityLifeCycleDispatcher() { 34 | mCallbacks = new CopyOnWriteArray(); 35 | } 36 | 37 | public void registerActivityLifeCycleCallback(IActivityLifeCycleCallback... callbacks) { 38 | CopyOnWriteArray mCallbacks = this.mCallbacks; 39 | for (IActivityLifeCycleCallback callback : callbacks) { 40 | if (!mCallbacks.contains(callback)) 41 | mCallbacks.add(callback); 42 | } 43 | } 44 | 45 | public void unregisterActivityLifeCycleCallback(IActivityLifeCycleCallback... callbacks) { 46 | CopyOnWriteArray mCallbacks = this.mCallbacks; 47 | for (IActivityLifeCycleCallback callback : callbacks) { 48 | mCallbacks.remove(callback); 49 | } 50 | } 51 | 52 | public boolean containsActivityLifeCycleCallback(IActivityLifeCycleCallback callback) { 53 | return mCallbacks.contains(callback); 54 | } 55 | 56 | //==============================// 57 | @CalledInternal 58 | public void dispatchActivityOnCreate(Activity activity, Bundle savedInstanceState) { 59 | //activity.getWindow().getDecorView().getViewTreeObserver() 60 | final CopyOnWriteArray listeners = mCallbacks; 61 | if (listeners.size() > 0) { 62 | CopyOnWriteArray.Access access = listeners.start(); 63 | try { 64 | int count = access.size(); 65 | for (int i = 0; i < count; i++) { 66 | access.get(i).onActivityCreate(activity, savedInstanceState); 67 | } 68 | } finally { 69 | listeners.end(); 70 | } 71 | } 72 | } 73 | 74 | @CalledInternal 75 | public void dispatchActivityOnPostCreate(Activity activity, Bundle savedInstanceState) { 76 | 77 | final CopyOnWriteArray listeners = mCallbacks; 78 | if (listeners.size() > 0) { 79 | CopyOnWriteArray.Access access = listeners.start(); 80 | try { 81 | int count = access.size(); 82 | for (int i = 0; i < count; i++) { 83 | access.get(i).onActivityPostCreate(activity, savedInstanceState); 84 | } 85 | } finally { 86 | listeners.end(); 87 | } 88 | } 89 | } 90 | 91 | @CalledInternal 92 | public void dispatchActivityOnStart(Activity activity) { 93 | final CopyOnWriteArray listeners = mCallbacks; 94 | if (listeners.size() > 0) { 95 | CopyOnWriteArray.Access access = listeners.start(); 96 | try { 97 | int count = access.size(); 98 | for (int i = 0; i < count; i++) { 99 | access.get(i).onActivityStart(activity); 100 | } 101 | } finally { 102 | listeners.end(); 103 | } 104 | } 105 | } 106 | 107 | @CalledInternal 108 | public void dispatchActivityOnResume(Activity activity) { 109 | final CopyOnWriteArray listeners = mCallbacks; 110 | if (listeners.size() > 0) { 111 | CopyOnWriteArray.Access access = listeners.start(); 112 | try { 113 | int count = access.size(); 114 | for (int i = 0; i < count; i++) { 115 | access.get(i).onActivityResume(activity); 116 | } 117 | } finally { 118 | listeners.end(); 119 | } 120 | } 121 | } 122 | 123 | @CalledInternal 124 | public void dispatchActivityOnPause(Activity activity) { 125 | final CopyOnWriteArray listeners = mCallbacks; 126 | if (listeners.size() > 0) { 127 | CopyOnWriteArray.Access access = listeners.start(); 128 | try { 129 | int count = access.size(); 130 | for (int i = 0; i < count; i++) { 131 | access.get(i).onActivityPause(activity); 132 | } 133 | } finally { 134 | listeners.end(); 135 | } 136 | } 137 | } 138 | 139 | @CalledInternal 140 | public void dispatchActivityOnStop(Activity activity) { 141 | final CopyOnWriteArray listeners = mCallbacks; 142 | if (listeners.size() > 0) { 143 | CopyOnWriteArray.Access access = listeners.start(); 144 | try { 145 | int count = access.size(); 146 | for (int i = 0; i < count; i++) { 147 | access.get(i).onActivityStop(activity); 148 | } 149 | } finally { 150 | listeners.end(); 151 | } 152 | } 153 | } 154 | 155 | @CalledInternal 156 | public void dispatchActivityOnDestroy(Activity activity) { 157 | final CopyOnWriteArray listeners = mCallbacks; 158 | if (listeners.size() > 0) { 159 | CopyOnWriteArray.Access access = listeners.start(); 160 | try { 161 | int count = access.size(); 162 | for (int i = 0; i < count; i++) { 163 | access.get(i).onActivityDestroy(activity); 164 | } 165 | } finally { 166 | listeners.end(); 167 | } 168 | } 169 | } 170 | 171 | @CalledInternal 172 | public void dispatchActivityOnConfigurationChanged(Activity activity, Configuration newConfig) { 173 | final CopyOnWriteArray listeners = mCallbacks; 174 | if (listeners.size() > 0) { 175 | CopyOnWriteArray.Access access = listeners.start(); 176 | try { 177 | int count = access.size(); 178 | for (int i = 0; i < count; i++) { 179 | access.get(i).onActivityConfigurationChanged(activity, newConfig); 180 | } 181 | } finally { 182 | listeners.end(); 183 | } 184 | } 185 | } 186 | 187 | @CalledInternal 188 | public void dispatchActivityOnUserLeaveHint(Activity activity) { 189 | final CopyOnWriteArray listeners = mCallbacks; 190 | if (listeners.size() > 0) { 191 | CopyOnWriteArray.Access access = listeners.start(); 192 | try { 193 | int count = access.size(); 194 | for (int i = 0; i < count; i++) { 195 | access.get(i).onActivityUserLeaveHint(activity); 196 | } 197 | } finally { 198 | listeners.end(); 199 | } 200 | } 201 | } 202 | 203 | @CalledInternal 204 | public void dispatchActivityOnActivityResult(Activity activity, 205 | int requestCode, int resultCode, Intent data) { 206 | final CopyOnWriteArray listeners = mCallbacks; 207 | if (listeners.size() > 0) { 208 | CopyOnWriteArray.Access access = listeners.start(); 209 | try { 210 | int count = access.size(); 211 | for (int i = 0; i < count; i++) { 212 | access.get(i).onActivityResult(activity, requestCode, resultCode, data); 213 | } 214 | } finally { 215 | listeners.end(); 216 | } 217 | } 218 | } 219 | 220 | @CalledInternal 221 | public void dispatchActivityOnActivityPermissionResult(Activity activity, 222 | int requestCode, @NonNull String[] permissions, @NonNull int[] grantResult) { 223 | final CopyOnWriteArray listeners = mCallbacks; 224 | if (listeners.size() > 0) { 225 | CopyOnWriteArray.Access access = listeners.start(); 226 | try { 227 | int count = access.size(); 228 | for (int i = 0; i < count; i++) { 229 | access.get(i).onRequestPermissionsResult(activity, requestCode, permissions, grantResult); 230 | } 231 | } finally { 232 | listeners.end(); 233 | } 234 | } 235 | } 236 | 237 | @CalledInternal 238 | public void dispatchActivityOnLowMemory(Activity activity) { 239 | final CopyOnWriteArray listeners = mCallbacks; 240 | if (listeners.size() > 0) { 241 | CopyOnWriteArray.Access access = listeners.start(); 242 | try { 243 | int count = access.size(); 244 | for (int i = 0; i < count; i++) { 245 | access.get(i).onActivityLowMemory(activity); 246 | } 247 | } finally { 248 | listeners.end(); 249 | } 250 | } 251 | } 252 | 253 | @CalledInternal 254 | public void dispatchActivityOnWindowFocusChanged( 255 | Activity activity, boolean hasFocus) { 256 | final CopyOnWriteArray listeners = mCallbacks; 257 | if (listeners.size() > 0) { 258 | CopyOnWriteArray.Access access = listeners.start(); 259 | try { 260 | int count = access.size(); 261 | for (int i = 0; i < count; i++) { 262 | access.get(i).onActivityWindowFocusChanged(activity, hasFocus); 263 | } 264 | } finally { 265 | listeners.end(); 266 | } 267 | } 268 | } 269 | 270 | } 271 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/lifecycle/IActivityLifeCycleCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.lifecycle; 18 | 19 | import android.app.Activity; 20 | import android.content.Intent; 21 | import android.content.res.Configuration; 22 | import android.os.Bundle; 23 | 24 | import org.heaven7.scrap.core.oneac.ScrapHelper; 25 | 26 | /** 27 | * Activity life cycle callback. if you want track the method of them.please call {@link ScrapHelper#registerActivityLifeCycleCallback(IActivityLifeCycleCallback...)} 28 | * and {@link ScrapHelper#unregisterActivityLifeCycleCallback(IActivityLifeCycleCallback...)} 29 | * @author heaven7 30 | */ 31 | public interface IActivityLifeCycleCallback { 32 | 33 | void onActivityCreate(Activity activity, Bundle savedInstanceState); 34 | void onActivityPostCreate(Activity activity, Bundle savedInstanceState); 35 | 36 | void onActivityStart(Activity activity); 37 | void onActivityResume(Activity activity); 38 | 39 | void onActivityPause(Activity activity); 40 | void onActivityStop(Activity activity); 41 | void onActivityDestroy(Activity activity); 42 | 43 | void onActivityConfigurationChanged(Activity activity, Configuration newConfig); 44 | 45 | void onActivityUserLeaveHint(Activity activity); 46 | 47 | void onActivityResult(Activity activity, int requestCode, int resultCode, 48 | Intent data); 49 | 50 | void onActivityLowMemory(Activity activity); 51 | 52 | void onActivityWindowFocusChanged(Activity activity, boolean hasFocus); 53 | 54 | void onRequestPermissionsResult(Activity activity, int requestCode, String[] permissions, int[] grantResult); 55 | } 56 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/ActivityController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.oneac; 18 | 19 | import android.app.Activity; 20 | import android.content.Context; 21 | import android.os.Bundle; 22 | import android.view.View; 23 | import android.view.ViewGroup; 24 | 25 | import androidx.annotation.RestrictTo; 26 | 27 | import com.heaven7.java.base.anno.CalledInternal; 28 | import com.heaven7.java.base.util.Reflector; 29 | 30 | import org.heaven7.scrap.core.ScrapConstant; 31 | import org.heaven7.scrap.core.anim.AnimateExecutor; 32 | import org.heaven7.scrap.core.event.ActivityEventAdapter; 33 | import org.heaven7.scrap.core.event.ActivityEventCallbackGroup; 34 | import org.heaven7.scrap.core.event.IActivityEventCallback; 35 | import org.heaven7.scrap.core.lifecycle.ActivityLifeCycleDispatcher; 36 | import org.heaven7.scrap.util.Utils; 37 | 38 | import java.util.Properties; 39 | 40 | /** 41 | * the controller of 'one-activity'. contains: lifeCycle({@link ActivityLifeCycleDispatcher}) and 42 | * event ( {@link ActivityEventCallbackGroup}) and the view controller({@link ActivityViewController}) 43 | * 44 | * @author heaven7 45 | * @see ActivityViewController 46 | * @see ActivityLifeCycleDispatcher 47 | * @see ActivityEventCallbackGroup 48 | */ 49 | public final class ActivityController { 50 | 51 | private static class Creator { 52 | public static final ActivityController INSTANCE = new ActivityController(); 53 | } 54 | /** 55 | * the activity's view controller 56 | */ 57 | private final ActivityViewController mViewController; 58 | /** 59 | * the activity's life cycle controller 60 | */ 61 | private final ActivityLifeCycleDispatcher mLifeCycleDispatcher; 62 | /** 63 | * the activity's event listener controller 64 | */ 65 | private final ActivityEventCallbackGroup mEventDispatcher; 66 | 67 | private final IActivityEventCallback mDefaultLastListener; 68 | private Bundle mSaveInstanceState; 69 | 70 | private ActivityController() { 71 | mViewController = new ActivityViewController(); 72 | mLifeCycleDispatcher = new ActivityLifeCycleDispatcher(); 73 | mEventDispatcher = new ActivityEventCallbackGroup(); 74 | mDefaultLastListener = new ActivityEventAdapter() { 75 | @Override 76 | public boolean onBackPressed() { 77 | BaseScrapView v = mViewController.getCurrentView(); 78 | if (v != null && v.onBackPressed()) { 79 | return true; 80 | } 81 | return mViewController.onBackPressed(); 82 | } 83 | }; 84 | mEventDispatcher.setActivityLastEventListener(mDefaultLastListener); 85 | } 86 | 87 | /** 88 | * obtain the single instance of ActivityController 89 | */ 90 | public static ActivityController get() { 91 | return Creator.INSTANCE; 92 | } 93 | 94 | /** 95 | * reset the all event listener of the activity. 96 | */ 97 | public void resetAllActivityEventListeners() { 98 | mEventDispatcher.clear(); 99 | mEventDispatcher.setActivityLastEventListener(mDefaultLastListener); 100 | } 101 | 102 | /** 103 | * this will be called automatic is the one Activity.* 104 | */ 105 | @CalledInternal 106 | @RestrictTo(RestrictTo.Scope.LIBRARY) 107 | public void attach(Activity activity, ViewGroup content, Bundle savedInstanceState) { 108 | mSaveInstanceState = savedInstanceState != null ? new Bundle(savedInstanceState) : null; 109 | mViewController.attachActivity(activity); 110 | mViewController.attachContainers(content); 111 | //if comes from save- State 112 | if(!getViewController().onRestoreInstanceState(mSaveInstanceState)){ 113 | jumpToMainScrapViewIfNeed(activity); 114 | } 115 | } 116 | 117 | /** 118 | * jump to the main scrap view 119 | */ 120 | private void jumpToMainScrapViewIfNeed(Activity activity) { 121 | if (activity == null) return; 122 | Properties prop = null; 123 | try { 124 | prop = Utils.loadRawConfig(activity, ScrapConstant.CONFIG_FILENAME); 125 | } catch (RuntimeException e) { 126 | //ignore 127 | } 128 | if (prop != null) { 129 | String classname = prop.getProperty(ScrapConstant.CONFIG_KEY_MAIN_SCRAP_VIEW); 130 | if (classname != null) { 131 | try { 132 | String backStack = prop.getProperty(ScrapConstant.CONFIG_KEY_MAIN_SCRAP_VIEW_BACK_STACK); 133 | BaseScrapView view = Reflector.from(Class.forName(classname)).constructor(Context.class) 134 | .newInstance(activity); 135 | if (!Boolean.valueOf(backStack)) { 136 | jumpTo(view); 137 | } else { 138 | beginTransaction().addBackAsBottom(view).jump().commit(); 139 | } 140 | } catch (ClassNotFoundException e) { 141 | throw new RuntimeException("Get error while load main scrap view , classname = " + classname, e); 142 | } 143 | } 144 | } 145 | } 146 | 147 | /** 148 | * get the bundle data of activity's save instance. 149 | * this comes from Activity_onCreate(savedInstanceState). 150 | * 151 | * @return the save instance data ,may be null if activity is finished. 152 | */ 153 | public Bundle getSaveInstanceData() { 154 | return mSaveInstanceState; 155 | } 156 | 157 | /** 158 | * return the attached activity. may be null if the activity not attached or is finished 159 | */ 160 | public Activity getActivity() { 161 | return mViewController.getActivity(); 162 | } 163 | 164 | /** 165 | * get the life cycle dispatcher/controller 166 | */ 167 | public ActivityLifeCycleDispatcher getLifeCycleDispatcher() { 168 | return mLifeCycleDispatcher; 169 | } 170 | 171 | /** 172 | * get the activity event listener group 173 | */ 174 | public ActivityEventCallbackGroup getEventListenerGroup() { 175 | return mEventDispatcher; 176 | } 177 | 178 | /** 179 | * get the view controller of the one activity. 180 | */ 181 | public ActivityViewController getViewController() { 182 | return mViewController; 183 | } 184 | 185 | /** 186 | * finish the activity which is attached into controller. 187 | * 188 | * @see ActivityViewController#finishActivity() 189 | */ 190 | public void finishActivity() { 191 | mViewController.finishActivity(); 192 | } 193 | 194 | //=================== about jump ================= // 195 | 196 | /** 197 | * jump to the target view with no data 198 | */ 199 | public void jumpTo(BaseScrapView view) { 200 | jumpTo(view, null); 201 | } 202 | 203 | /** 204 | * jump to the target view with data. 205 | * 206 | * @param view the view to jump 207 | * @param data the data to carry. 208 | */ 209 | public void jumpTo(BaseScrapView view, Bundle data) { 210 | mViewController.jumpTo(view, data); 211 | } 212 | 213 | /** 214 | * open the transaction of {@link ActivityViewController}, this is very useful. 215 | * here is the sample code:

216 | *

 Transaction transaction = ActivityController.get().beginTransaction();
217 |      *       transaction.cache(view).stackMode(Mode.ReplacePreviousAndClearAfter)
218 |      *           .addBackAsTop().jump().commit();
219 |      *  

220 | * the more to see {@link Transaction} 221 | * 222 | * @see Transaction 223 | */ 224 | public Transaction beginTransaction() { 225 | return mViewController.beginTransaction(); 226 | } 227 | 228 | // =============== other ====================// 229 | 230 | /** 231 | * set the animation executor which used to pass one {@link BaseScrapView} to another BaseScrapView 232 | * 233 | * @param executor the animate executor 234 | */ 235 | public void setAnimateExecutor(AnimateExecutor executor) { 236 | mViewController.setAnimateExecutor(executor); 237 | } 238 | 239 | } 240 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/CacheHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.oneac; 18 | 19 | import android.content.Context; 20 | import android.os.Bundle; 21 | 22 | import com.heaven7.java.base.util.Reflector; 23 | 24 | import java.util.Collections; 25 | import java.util.Comparator; 26 | import java.util.HashMap; 27 | import java.util.List; 28 | import java.util.Map; 29 | import java.util.NoSuchElementException; 30 | 31 | /** 32 | * the cache helper for internal use. 33 | * the view stack only cache one instance of the same class name which is a child of BaseScrapView. 34 | * if {@link ExpandArrayList#getMode()} != {@link StackMode#Normal} 35 | *
  • you can use {@link Transaction#stackMode(StackMode)} to change the default behavior. and the {@link Transaction#commit()} will restore mode 36 | * to default({@link StackMode#ClearPrevious}). 37 | * @see Transaction#stackMode(StackMode) 38 | * @see Transaction#commit() 39 | * @author heaven7 40 | */ 41 | /* package */ final class CacheHelper { 42 | 43 | private static final String KEY_STACK_PREFIX = "stack_"; 44 | private static final String KEY_CACHE_PREFIX = "cache_"; 45 | private static final String KEY_SIZE = "size_"; 46 | private static final String KEY_CLASS = "class_"; 47 | private static final String KEY_DATA = "data_"; 48 | private static final String KEY_MAP_KEY = "key_"; 49 | private static final String KEY_CUR_INDEX = "curIndex_"; 50 | 51 | final ExpandArrayList mViewStack; 52 | private final HashMap mCachedViewMap; 53 | 54 | private static final Comparator DEFAULT_COMPARATOR = new Comparator() { 55 | @Override 56 | public int compare(BaseScrapView lhs, BaseScrapView rhs) { 57 | return lhs.compareTo(rhs); 58 | } 59 | }; 60 | 61 | public CacheHelper() { 62 | mCachedViewMap = new HashMap(); 63 | mViewStack = new ExpandArrayList(){ 64 | @Override 65 | public boolean add(BaseScrapView baseScrapView) { 66 | if(!baseScrapView.isInBackStack()) 67 | baseScrapView.setInBackStack(true); 68 | return super.add(baseScrapView); 69 | } 70 | @Override 71 | public void add(int index, BaseScrapView baseScrapView) { 72 | if(!baseScrapView.isInBackStack()) 73 | baseScrapView.setInBackStack(true); 74 | super.add(index, baseScrapView); 75 | } 76 | }; 77 | // set Comparator to prevent the same class 78 | mViewStack.setComparator(DEFAULT_COMPARATOR); 79 | mViewStack.setStackMode(StackMode.Normal); 80 | } 81 | 82 | /** restore the setting of back stack. */ 83 | public void resetStackSetting(){ 84 | if(mViewStack.getComparator() != DEFAULT_COMPARATOR){ 85 | mViewStack.setComparator(DEFAULT_COMPARATOR); 86 | } 87 | if(mViewStack.getMode() != StackMode.Normal) 88 | mViewStack.setStackMode(StackMode.Normal); 89 | } 90 | 91 | public List getStackList() { 92 | return Collections.unmodifiableList(mViewStack); 93 | } 94 | 95 | /** 96 | * make the BaseScrapView in the cache for reuse. 97 | * @param key the key to find for resue. 98 | * @param view which view you want to cache 99 | */ 100 | public CacheHelper cache(String key, BaseScrapView view){ 101 | if(view == null) 102 | throw new NullPointerException(); 103 | mCachedViewMap.put(key, view); 104 | return this; 105 | } 106 | 107 | /** default key is the view.getClass().getName()*/ 108 | public CacheHelper cache(BaseScrapView view){ 109 | return cache(view.getClass().getName(), view); 110 | } 111 | 112 | public BaseScrapView getCacheView(String key){ 113 | return mCachedViewMap.get(key); 114 | } 115 | 116 | /** remove the mapping of the key 117 | * @param key */ 118 | public BaseScrapView removeCacheView(String key){ 119 | return mCachedViewMap.remove(key); 120 | } 121 | 122 | /** 123 | * add view to the top of stack. it means it will be first removed from next first back event. 124 | * @param view 125 | */ 126 | public CacheHelper addToStackTop(BaseScrapView view){ 127 | mViewStack.addLast(view); 128 | return this; 129 | } 130 | /** 131 | * add view to the bottom of stack. it means it will be last removed from back stack.. 132 | * @param view 133 | */ 134 | public CacheHelper addToStackBottom(BaseScrapView view){ 135 | mViewStack.addFirst(view); 136 | return this; 137 | } 138 | 139 | /** 140 | * @return the size of back stack. 141 | */ 142 | public int getStackSize(){ 143 | return mViewStack.size(); 144 | } 145 | 146 | public BaseScrapView pollStackTail(){ 147 | BaseScrapView view = mViewStack.pollLast(); 148 | view.setInBackStack(false); 149 | return view; 150 | } 151 | 152 | public BaseScrapView pollStackHead(){ 153 | BaseScrapView view = mViewStack.pollFirst(); 154 | view.setInBackStack(false); 155 | return view; 156 | } 157 | 158 | /** get the bottom of stack.*/ 159 | public BaseScrapView getStackHead(){ 160 | return mViewStack.getFirst(); 161 | } 162 | 163 | public void clearStack(){ 164 | mViewStack.clear(); 165 | } 166 | public void clearCache(){ 167 | mCachedViewMap.clear(); 168 | } 169 | 170 | public void clearAll(){ 171 | mCachedViewMap.clear(); 172 | mViewStack.clear(); 173 | } 174 | /** 175 | * add the view to stack befor or after the referencedView. 176 | * @param referencedView the view to referenced 177 | * @param target the target view to add 178 | * @param before true to make the view before referencedView.false to after it. 179 | * @throws NoSuchElementException if referencedView isn't in stack. 180 | */ 181 | public void addToStack(BaseScrapView referencedView, BaseScrapView target, 182 | boolean before) { 183 | if(before) 184 | mViewStack.addBefore(referencedView, target); 185 | else 186 | mViewStack.addAfter(referencedView, target); 187 | } 188 | /** 189 | * add the view to stack befor or after the referencedView. 190 | * @param referencedClass the referencedClass of BaseScrapView 191 | * @param target the view to add 192 | * @param before true to make the view before referencedView.false to after it. 193 | * @throws NoSuchElementException if the referencedView isn't in stack. 194 | */ 195 | /*public*/ void addToStack(Class referencedClass, BaseScrapView target, 196 | boolean before) { 197 | //create a simulate BaseScrapView to indexOf 198 | BaseScrapView referencedView = Reflector.from(referencedClass).constructor(Context.class) 199 | .newInstance(target.getContext()); 200 | addToStack(referencedView, target, before); 201 | } 202 | 203 | public void onSaveInstanceState(Bundle out, int curIndex) { 204 | //save stack 205 | int size = mViewStack.size(); 206 | out.putInt(KEY_STACK_PREFIX + KEY_SIZE, size); 207 | out.putInt(KEY_STACK_PREFIX + KEY_CUR_INDEX, curIndex); 208 | for (int i = 0 ; i < size ; i ++){ 209 | BaseScrapView view = mViewStack.get(i); 210 | Bundle b = new Bundle(); 211 | view.onSaveInstanceState(b); 212 | out.putBundle(KEY_STACK_PREFIX + KEY_DATA + i, b); 213 | out.putString(KEY_STACK_PREFIX + KEY_CLASS + i, view.getClass().getName()); 214 | } 215 | //save cache 216 | size = mCachedViewMap.size(); 217 | out.putInt(KEY_CACHE_PREFIX + KEY_SIZE, size); 218 | int i = 0; 219 | for (Map.Entry en : mCachedViewMap.entrySet()){ 220 | BaseScrapView view = en.getValue(); 221 | 222 | Bundle b = new Bundle(); 223 | view.onSaveInstanceState(b); 224 | out.putBundle(KEY_CACHE_PREFIX + KEY_DATA + i, b); 225 | out.putString(KEY_CACHE_PREFIX + KEY_CLASS + i, view.getClass().getName()); 226 | out.putString(KEY_CACHE_PREFIX + KEY_MAP_KEY + i, en.getKey()); 227 | i ++; 228 | } 229 | } 230 | public int onRestoreInstanceState(Context context, Bundle in) { 231 | int curIndex = -2; 232 | if(in != null){ 233 | int size = in.getInt(KEY_STACK_PREFIX + KEY_SIZE); 234 | curIndex = in.getInt(KEY_STACK_PREFIX + KEY_CUR_INDEX); 235 | mViewStack.clear(); 236 | for (int i = 0 ; i < size ; i++){ 237 | String cn = in.getString(KEY_STACK_PREFIX + KEY_CLASS + i); 238 | Bundle b = in.getBundle(KEY_STACK_PREFIX + KEY_DATA + i); 239 | try { 240 | BaseScrapView view = Reflector.from(Class.forName(cn)).constructor(Context.class).newInstance(context); 241 | view.onRestoreInstanceState(b); 242 | mViewStack.add(view); 243 | } catch (ClassNotFoundException e) { 244 | throw new IllegalStateException(e); 245 | } 246 | } 247 | //restore cache 248 | mCachedViewMap.clear(); 249 | size = in.getInt(KEY_CACHE_PREFIX + KEY_SIZE); 250 | for (int i = 0 ; i < size ; i ++){ 251 | Bundle b = in.getBundle(KEY_CACHE_PREFIX + KEY_DATA + i); 252 | String cn = in.getString(KEY_CACHE_PREFIX + KEY_CLASS + i); 253 | String mapKey = in.getString(KEY_CACHE_PREFIX + KEY_MAP_KEY + i); 254 | 255 | try { 256 | BaseScrapView view = Reflector.from(Class.forName(cn)).constructor(Context.class).newInstance(context); 257 | view.onRestoreInstanceState(b); 258 | mCachedViewMap.put(mapKey, view); 259 | } catch (ClassNotFoundException e) { 260 | throw new IllegalStateException(e); 261 | } 262 | } 263 | } 264 | return curIndex; 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/ExpandArrayList.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.oneac; 2 | 3 | import org.heaven7.scrap.util.ArrayList2; 4 | 5 | import java.io.IOException; 6 | import java.io.InvalidObjectException; 7 | import java.io.ObjectInputStream; 8 | import java.io.ObjectOutputStream; 9 | import java.util.Comparator; 10 | 11 | /** 12 | * an expand ArrayList2 . use {@link #setStackMode(StackMode)} and {@link #setComparator(Comparator)} will be useful to control how to add new E 13 | * and will effect add(E) , add(index,E) 14 | * 15 | * @param 16 | * @author heaven7 17 | * @see StackMode 18 | * @see ExpandArrayList#add(Object) 19 | * @see ExpandArrayList#add(int, Object) 20 | */ 21 | /*public*/ class ExpandArrayList extends ArrayList2 { 22 | private static final long serialVersionUID = -8201458809772301953L; 23 | 24 | private StackMode mMode = StackMode.Normal; 25 | private Comparator mComparator; 26 | 27 | public StackMode getMode() { 28 | return mMode; 29 | } 30 | 31 | /** 32 | * set the mode which will effect the 'add(E)' and 'add(index,E)' operation. 33 | * default is {@link StackMode#Normal} 34 | * 35 | * @param mode can't be null 36 | */ 37 | public void setStackMode(StackMode mode) { 38 | if (mode == null) 39 | throw new NullPointerException(); 40 | this.mMode = mode; 41 | } 42 | 43 | public Comparator getComparator() { 44 | return mComparator; 45 | } 46 | 47 | /** 48 | * set the comparator , which will indicate how to find E. so effect {@link #indexOf(Object)} directly. 49 | * if {@link #getMode()} == {@link StackMode#Normal},this have no effect. 50 | */ 51 | public void setComparator(Comparator c) { 52 | this.mComparator = c; 53 | } 54 | 55 | @Override 56 | public boolean add(E e) { 57 | if (e == null) 58 | throw new NullPointerException(); 59 | 60 | switch (mMode) { 61 | case ClearPrevious: 62 | int index = indexOf(e); 63 | if (index != -1) { 64 | remove(index); 65 | } 66 | return super.add(e); 67 | 68 | case ReplacePrevious: 69 | int index2 = indexOf(e); 70 | if (index2 != -1) { 71 | set(index2, e); 72 | return true; 73 | } 74 | return super.add(e); 75 | 76 | case ReplacePreviousAndClearAfter: 77 | int index3 = indexOf(e); 78 | if (index3 != -1) { 79 | set(index3, e); 80 | clearAfter(index3); 81 | return true; 82 | } 83 | return super.add(e); 84 | 85 | case Normal: 86 | default: 87 | return super.add(e); 88 | } 89 | } 90 | 91 | @Override //index to add 92 | public void add(int index, E e) { 93 | if (e == null) 94 | throw new NullPointerException(); 95 | 96 | switch (mMode) { 97 | 98 | case ClearPrevious: 99 | int oldIndex = indexOf(e); 100 | super.add(index, e); 101 | if (oldIndex == -1) { 102 | break; 103 | } 104 | //" oldIndex >= index " indicate the delete index after(>=) the added index 105 | final boolean after = oldIndex >= index; 106 | remove(after ? oldIndex + 1 : oldIndex); 107 | break; 108 | 109 | case ReplacePrevious: 110 | int index2 = indexOf(e); 111 | if (index2 != -1) { 112 | set(index2, e); 113 | break; 114 | } 115 | super.add(index, e); 116 | break; 117 | 118 | case ReplacePreviousAndClearAfter: 119 | int index3 = indexOf(e); 120 | if (index3 != -1) { 121 | set(index3, e); 122 | clearAfter(index3); 123 | break; 124 | } 125 | super.add(index, e); 126 | break; 127 | 128 | case Normal: 129 | default: 130 | super.add(index, e); 131 | } 132 | } 133 | 134 | /** 135 | * clear all element whose index after index 136 | */ 137 | private void clearAfter(int index) { 138 | removeRange(index + 1, size()- 1); 139 | } 140 | 141 | @SuppressWarnings("unchecked") 142 | @Override 143 | public int indexOf(Object object) { 144 | if (object == null) 145 | return -1; 146 | E target = null; 147 | try { 148 | target = (E) object; 149 | } catch (ClassCastException e) { 150 | return -1; 151 | } 152 | final Comparator comparator = this.mComparator; 153 | 154 | final int size = size(); 155 | int index = -1; 156 | for (int i = 0; i < size; i++) { 157 | E e = get(i); 158 | if (comparator == null) { 159 | if (e.equals(object)) { 160 | index = i; 161 | break; 162 | } 163 | } else if (comparator.compare(e, target) == 0) { 164 | index = i; 165 | break; 166 | } 167 | } 168 | return index; 169 | } 170 | 171 | private void writeObject(ObjectOutputStream stream) throws IOException { 172 | stream.defaultWriteObject(); 173 | stream.writeInt(mMode.value); 174 | 175 | final int size = size(); 176 | stream.writeInt(size); 177 | for (int i = 0; i < size; i++) { 178 | stream.writeObject(get(i)); 179 | } 180 | } 181 | 182 | @SuppressWarnings("unchecked") 183 | private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { 184 | stream.defaultReadObject(); 185 | int modeVlue = stream.readInt(); 186 | this.mMode = convertToMode(modeVlue); 187 | 188 | final int size = size(); 189 | int cap = stream.readInt(); 190 | if (cap < size) { 191 | throw new InvalidObjectException( 192 | "Capacity: " + cap + " < size: " + size); 193 | } 194 | clear(); 195 | trimToSize(); 196 | // array = (cap == 0 ? EmptyArray.OBJECT : new Object[cap]); 197 | for (int i = 0; i < size; i++) { 198 | //array[i] = stream.readObject(); 199 | add((E) stream.readObject()); 200 | } 201 | } 202 | 203 | public static StackMode convertToMode(int modeVlue) { 204 | switch (modeVlue) { 205 | case 1: 206 | return StackMode.Normal; 207 | 208 | case 2: 209 | return StackMode.ClearPrevious; 210 | 211 | case 3: 212 | return StackMode.ReplacePrevious; 213 | 214 | case 4: 215 | return StackMode.ReplacePreviousAndClearAfter; 216 | 217 | default: 218 | throw new IllegalStateException("wrong mode = " + modeVlue); 219 | } 220 | } 221 | } -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/IBackEventProcessor.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.oneac; 2 | 3 | /** 4 | * the back event handler 5 | * Created by heaven7 on 2015/8/3. 6 | */ 7 | public interface IBackEventProcessor{ 8 | 9 | /** 10 | * handle the back event . 11 | * @return true to consume the back event. 12 | */ 13 | boolean handleBackEvent(); 14 | } 15 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/IntentExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.oneac; 18 | 19 | import android.content.Context; 20 | 21 | /** 22 | * Created by heaven7 on 2015/8/1. 23 | */ 24 | public interface IntentExecutor { 25 | /** 26 | * start activity with the context 27 | * @param context the context 28 | */ 29 | void startActivity(Context context); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/LoadingParam.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.oneac; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | /** 7 | * loading param , used for the loading view 8 | * Created by heaven7 on 2015/8/9. 9 | */ 10 | public class LoadingParam implements Parcelable { 11 | 12 | public boolean showLoading; 13 | public boolean showTop; 14 | public boolean showBottom; 15 | 16 | // public boolean showMiddle; 17 | //content/middle is not show ,if showLoading = true 18 | 19 | /** 20 | * @param showLoading true to show loading 21 | * @param showTop true to show top while showLoading = true, 22 | * @param showBottom true to show bottom while showLoading = true; 23 | */ 24 | public LoadingParam(boolean showLoading, boolean showTop, boolean showBottom) { 25 | set(showLoading,showTop,showBottom); 26 | } 27 | 28 | /** 29 | * @param showLoading true to show loading 30 | * @param showTop true to show top while showLoading = true, 31 | * @param showBottom true to show bottom while showLoading = true; 32 | */ 33 | public void set(boolean showLoading, boolean showTop, boolean showBottom){ 34 | this.showLoading = showLoading; 35 | this.showTop = showTop; 36 | this.showBottom = showBottom; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "LoadingParam{" + 42 | "showLoading=" + showLoading + 43 | ", showTop=" + showTop + 44 | ", showBottom=" + showBottom + 45 | '}'; 46 | } 47 | 48 | @Override 49 | public int describeContents() { 50 | return 0; 51 | } 52 | 53 | @Override 54 | public void writeToParcel(Parcel dest, int flags) { 55 | dest.writeByte(this.showLoading ? (byte) 1 : (byte) 0); 56 | dest.writeByte(this.showTop ? (byte) 1 : (byte) 0); 57 | dest.writeByte(this.showBottom ? (byte) 1 : (byte) 0); 58 | } 59 | 60 | protected LoadingParam(Parcel in) { 61 | this.showLoading = in.readByte() != 0; 62 | this.showTop = in.readByte() != 0; 63 | this.showBottom = in.readByte() != 0; 64 | } 65 | 66 | public static final Creator CREATOR = new Creator() { 67 | @Override 68 | public LoadingParam createFromParcel(Parcel source) { 69 | return new LoadingParam(source); 70 | } 71 | 72 | @Override 73 | public LoadingParam[] newArray(int size) { 74 | return new LoadingParam[size]; 75 | } 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/ScrapHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.core.oneac; 18 | 19 | import android.os.Bundle; 20 | 21 | import org.heaven7.scrap.core.anim.AnimateExecutor; 22 | import org.heaven7.scrap.core.event.IActivityEventCallback; 23 | import org.heaven7.scrap.core.lifecycle.IActivityLifeCycleCallback; 24 | 25 | /** 26 | * a helpful util to use the 'OneActivity' framework.such as: jump to different page of {@linkplain BaseScrapView} 27 | * if you want more ,please see {@link ActivityController} and {@link ActivityViewController}. 28 | *

    how to get them ?

    29 | *
    ActivityController controller = ActivityController.get();
     30 |  *     ActivityViewController viewController = controller.getViewController();
     31 |  *     ...// the more you want to do!
     32 |  * 
    33 | * @author heaven7 34 | * @see ActivityController 35 | * @see ActivityViewController 36 | * @see Transaction 37 | */ 38 | public final class ScrapHelper { 39 | 40 | /** jump to the target view with no data. */ 41 | public static void jumpTo(BaseScrapView view){ 42 | ActivityController.get().jumpTo(view); 43 | } 44 | 45 | /** 46 | * jump to the target view with data. but not cache it or add to back stack. 47 | * if you want more . please use {@link #beginTransaction()} 48 | * @param view the view to jump 49 | * @param data the data to carry. 50 | * @see Transaction 51 | */ 52 | public static void jumpTo(BaseScrapView view ,Bundle data){ 53 | ActivityController.get().jumpTo(view, data); 54 | } 55 | 56 | /** 57 | * jump to the target view with data and animate executor. 58 | * @param target the target to jump 59 | * @param data the data to carry 60 | * @param executor the animate executor to perform this jump(only use once) 61 | */ 62 | public static void jumpTo(BaseScrapView target,Bundle data,AnimateExecutor executor){ 63 | getActivityViewController().jumpTo(target,data,executor); 64 | } 65 | /** 66 | * jump to the target view with animate executor. 67 | * @param target the target to jump 68 | * @param executor the animate executor to perform this jump(only use once) 69 | */ 70 | public static void jumpTo(BaseScrapView target,AnimateExecutor executor){ 71 | getActivityViewController().jumpTo(target,null,executor); 72 | } 73 | 74 | /** 75 | * open the transaction of {@link ActivityViewController}, this is very useful. 76 | * here is the sample code:

    77 | *

     Transaction transaction = ActivityController.get().beginTransaction();
     78 |      *       transaction.cache(view).changeBackStackMode(ExpandArrayList2.Mode.ReplacePreviousAndClearAfter)
     79 |      *           .addBack().jump().commit();
     80 |      *  

    81 | * the more to see {@link Transaction} 82 | * @see Transaction 83 | */ 84 | public static Transaction beginTransaction(){ 85 | return ActivityController.get().beginTransaction(); 86 | } 87 | 88 | /** 89 | * register Activity life cycle callback. which will be call in the Activity. 90 | * also you can use {@link org.heaven7.scrap.core.lifecycle.ActivityLifeCycleAdapter} ,it implement IActivityLifeCycleCallback 91 | * @param callbacks the callbacks 92 | * @see IActivityLifeCycleCallback 93 | * @see org.heaven7.scrap.core.lifecycle.ActivityLifeCycleAdapter 94 | * @see org.heaven7.scrap.core.lifecycle.ActivityLifeCycleDispatcher 95 | */ 96 | public static void registerActivityLifeCycleCallback(IActivityLifeCycleCallback... callbacks){ 97 | ActivityController.get().getLifeCycleDispatcher().registerActivityLifeCycleCallback(callbacks); 98 | } 99 | 100 | /** 101 | * unregister the activity life cycle callback. suach as: Activity_onResume(),Activity_onStop() 102 | * @param callbacks the callbacks 103 | * @see #registerActivityLifeCycleCallback(IActivityLifeCycleCallback...) 104 | */ 105 | public static void unregisterActivityLifeCycleCallback(IActivityLifeCycleCallback...callbacks){ 106 | ActivityController.get().getLifeCycleDispatcher().unregisterActivityLifeCycleCallback(callbacks); 107 | } 108 | 109 | /** 110 | * register the event callback of Activity.such as: key event(down/up...etc).touch event. 111 | * also use can use {@link org.heaven7.scrap.core.event.ActivityEventAdapter} 112 | * @param callbacks the callbacks 113 | * @see IActivityEventCallback 114 | * @see org.heaven7.scrap.core.event.ActivityEventAdapter 115 | */ 116 | public static void registerActivityEventCallback(IActivityEventCallback ...callbacks){ 117 | ActivityController.get().getEventListenerGroup().registerActivityEventListener(callbacks); 118 | } 119 | 120 | /** 121 | * unregister the event callback of activity. 122 | * @param callbacks the callbacks 123 | * @see #registerActivityEventCallback(IActivityEventCallback...) 124 | */ 125 | public static void unregisterActivityEventCallback(IActivityEventCallback ...callbacks){ 126 | ActivityController.get().getEventListenerGroup().unregisterActivityEventListener(callbacks); 127 | } 128 | 129 | /** 130 | * whether or not the target scarp view is at the top of back stack. 131 | *
  • head means it will be removed from back stack with the next first back event.
  • 132 | * @param target the target view 133 | * @return true if the target is the head view of back stack. 134 | */ 135 | public static boolean isScrapViewAtTop(BaseScrapView target){ 136 | if(target == null) 137 | return false; 138 | return ActivityController.get().getViewController().getCurrentView() == target; 139 | } 140 | /** 141 | * whether or not the target scarp view is at the bottom of back stack. 142 | *
  • bottom means it will be last removed from back stack
  • 143 | * @param target the target view 144 | * @return true if the target at the bottom view of back stack. 145 | * false if the target is null or it not add to the back stack. 146 | * @see #isScrapViewAtTop(BaseScrapView) 147 | * @see Transaction#addBackAsBottom() 148 | */ 149 | public static boolean isScrapViewAtBottom(BaseScrapView target){ 150 | return ActivityController.get().getViewController().isScrapViewAtBottom(target); 151 | } 152 | 153 | /** finish the current activity which is attached to {@link ActivityController} */ 154 | public static void finishCurrentActivity(){ 155 | ActivityController.get().finishActivity(); 156 | } 157 | 158 | /** 159 | * get the activity's view controller 160 | */ 161 | public static ActivityViewController getActivityViewController(){ 162 | return ActivityController.get().getViewController(); 163 | } 164 | 165 | /** set the visible of view . 166 | * @param visible true to visible,false to gone. 167 | * */ 168 | public static void setVisibility(boolean visible){ 169 | getActivityViewController().setVisibility(visible); 170 | } 171 | 172 | /** 173 | * toggle the visibility of view . 174 | */ 175 | public static void toggleVisibility() { 176 | getActivityViewController().toggleVisibility(); 177 | } 178 | 179 | /** 180 | * set the animate executor when jump from one ScrapView to another. 181 | * @note this animate executor is used as the global . 182 | * @param animateExecutor the animate executor 183 | * @see AnimateExecutor the animate executor 184 | */ 185 | public static void setGlobalAnimateExecutor(AnimateExecutor animateExecutor) { 186 | ActivityController.get().setAnimateExecutor(animateExecutor); 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/StackMode.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.core.oneac; 2 | 3 | 4 | import org.heaven7.scrap.util.ArrayList2; 5 | 6 | import java.util.Comparator; 7 | 8 | /*** 9 | * the mode of operate indicate how to effect {@link ExpandArrayList#add(Object)} or {@link ExpandArrayList#add(int, Object)} 10 | * if {@link ExpandArrayList#indexOf(Object)} != -1. 11 | * @author heaven7 12 | * @see ExpandArrayList#add(Object) 13 | * @see ExpandArrayList#add(int, Object) 14 | * @see #Normal 15 | * @see #ClearPrevious 16 | * @see #ReplacePrevious 17 | * @see #ReplacePreviousAndClearAfter 18 | */ 19 | public enum StackMode { 20 | 21 | /** 22 | * have no effect. same to {@link ArrayList2} 23 | */ 24 | Normal(1), 25 | /** 26 | * use {@link ExpandArrayList#indexOf(Object)} to search previous ( as this behaviour depend on the Comparator 27 | * which can through {@link ExpandArrayList#setComparator(Comparator)} to change it). 28 | * clear the previous E and put new E at the end or the target index. 29 | * 30 | * @see ExpandArrayList#add(int, Object) 31 | * @see ExpandArrayList#indexOf(Object) 32 | */ 33 | ClearPrevious(2), 34 | /** 35 | * update the previous E to new E 36 | * 37 | * @see #ClearPrevious 38 | */ 39 | ReplacePrevious(3), 40 | /** 41 | * update the previous E to new E,and the All E after it will be cleared. 42 | * this is similar to Activity.launch-mode = top 43 | * 44 | * @see #ClearPrevious 45 | */ 46 | ReplacePreviousAndClearAfter(4); 47 | 48 | final int value; 49 | 50 | private StackMode(int value) { 51 | this.value = value; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/util/ArrayList2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.util; 18 | 19 | import java.util.ArrayList; 20 | import java.util.LinkedList; 21 | import java.util.NoSuchElementException; 22 | /** 23 | * a util similar to {@link ArrayList} help to use other feature. like {@link LinkedList} 24 | * and have another helpful methods.such as: {@link #addAfter(Object, Object)} and {@link #addBefore(Object, Object)} 25 | * @author heaven7 26 | * @param 27 | */ 28 | public class ArrayList2 extends ArrayList { 29 | 30 | private static final long serialVersionUID = 894057356164202818L; 31 | 32 | @Override 33 | public boolean add(E e) { 34 | if(e == null) 35 | throw new NullPointerException("in ArrayList2 or child of it Null element is not permit."); 36 | return super.add(e); 37 | } 38 | 39 | /** add e to the first .same as: {@link LinkedList#addFirst(Object)} */ 40 | public void addFirst(E e){ 41 | add(0, e); 42 | } 43 | /** add e to the last .same as: {@link LinkedList#addLast(Object)} */ 44 | public void addLast(E e){ 45 | add(size(), e); 46 | } 47 | /** 48 | * add the element E after the element of index. 49 | * @param index must >=0 50 | */ 51 | public void addAfter(int index, E e) { 52 | if(index < 0) 53 | throw new IllegalArgumentException("index is invalid(must >=0). index = " +index); 54 | add(index + 1, e); 55 | } 56 | /** 57 | * add an element after another element. 58 | * @param referenced the e to compare or refer. 59 | * @param e the e to add 60 | * @throws NoSuchElementException if the referenced e can't find. 61 | */ 62 | public void addAfter(E referenced, E e) throws NoSuchElementException{ 63 | int index = indexOf(referenced); //0 ~ size-1 64 | if(index == -1){ 65 | throw new NoSuchElementException(); 66 | } 67 | add(index + 1, e); 68 | } 69 | /** 70 | * add the element E before the element of index. 71 | * @param index must <= size() + 1 72 | */ 73 | public void addBefore(int index, E e){ 74 | if(index > size() + 1)//max = size+1 75 | throw new IllegalArgumentException(""); 76 | add(index <=0 ? 0 : index-1 , e); 77 | } 78 | /** 79 | * add an element before another element. 80 | * @param referenced the e to compare or refer. 81 | * @param e the e to add 82 | * @throws NoSuchElementException if the referenced e can't find. 83 | */ 84 | public void addBefore(E referenced, E e){ 85 | int index = indexOf(referenced); 86 | if(index == -1){ 87 | throw new NoSuchElementException(); 88 | } 89 | addBefore(index, e); 90 | } 91 | 92 | /** get and remove last element may be null if list is empty. */ 93 | public E pollLast() { 94 | int size = size(); 95 | return size !=0 ? remove(size -1) : null; 96 | } 97 | 98 | /** get and remove first element may be null if list is empty. */ 99 | public E pollFirst() { 100 | int size = size(); 101 | return size !=0 ? remove(0) :null; 102 | } 103 | 104 | /** get first element but not remove from list, may be null if list is empty. */ 105 | public E getFirst(){ 106 | int size = size(); 107 | return size !=0 ? get(0) :null; 108 | } 109 | /** get last element but not remove from list, may be null if list is empty. */ 110 | public E getLast(){ 111 | int size = size(); 112 | return size !=0 ? get(size-1) :null; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/util/SpringUtil.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.util; 2 | 3 | public final class SpringUtil { 4 | 5 | /** 6 | * Map a value within a given range to another range. 7 | * @param value the value to map 8 | * @param fromLow the low end of the range the value is within 9 | * @param fromHigh the high end of the range the value is within 10 | * @param toLow the low end of the range to map to 11 | * @param toHigh the high end of the range to map to 12 | * @return the mapped value 13 | */ 14 | public static double mapValueFromRangeToRange( 15 | double value, 16 | double fromLow, 17 | double fromHigh, 18 | double toLow, 19 | double toHigh) { 20 | double fromRangeSize = fromHigh - fromLow; 21 | double toRangeSize = toHigh - toLow; 22 | double valueScale = (value - fromLow) / fromRangeSize; 23 | return toLow + (valueScale * toRangeSize); 24 | } 25 | 26 | /** 27 | * Clamp a value to be within the provided range. 28 | * @param value the value to clamp 29 | * @param low the low end of the range 30 | * @param high the high end of the range 31 | * @return the clamped value 32 | */ 33 | public static double clamp(double value, double low, double high) { 34 | return Math.min(Math.max(value, low), high); 35 | } 36 | } -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/util/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 3 | * heaven7(donshine723@gmail.com) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.heaven7.scrap.util; 18 | 19 | import android.content.Context; 20 | import android.content.res.Resources; 21 | 22 | import androidx.annotation.RestrictTo; 23 | 24 | import com.heaven7.core.util.ConfigUtil; 25 | import com.heaven7.core.util.DimenUtil; 26 | import com.heaven7.core.util.ResourceUtil; 27 | 28 | import java.util.Properties; 29 | 30 | @RestrictTo(RestrictTo.Scope.LIBRARY) 31 | public final class Utils { 32 | 33 | private static int sSystemUIHeight; 34 | 35 | /** load properties which is under the raw (exclude extension )*/ 36 | public static Properties loadRawConfig(Context context,String rawResName) { 37 | int resId = ResourceUtil.getResId(context, rawResName, ResourceUtil.ResourceType.Raw); 38 | return ConfigUtil.loadRawConfig(context, resId); 39 | } 40 | 41 | public static int getSystemUIHeight(Context context) { 42 | if (0 == sSystemUIHeight) { 43 | Resources resources = context.getResources(); 44 | int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); 45 | if (resourceId > 0) { 46 | sSystemUIHeight = resources.getDimensionPixelSize(resourceId); 47 | } else { 48 | sSystemUIHeight = DimenUtil.dip2px(context, 56); 49 | } 50 | } 51 | return sSystemUIHeight; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/layout/lib_style_ac_container.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/layout/lib_style_ac_no_overlap.xml: -------------------------------------------------------------------------------- 1 | 4 | 10 | 11 | 18 | 19 | 20 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/layout/lib_style_ac_overlap.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 12 | 13 | 18 | 19 | 20 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/android-scrap/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/android-scrap/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/android-scrap/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/android-scrap/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Android-Scrap 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /Android-Scrap/android-scrap/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Android-Scrap/backup/ResourceHoldable.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.res; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | 6 | public interface ResourceHoldable { 7 | 8 | Context getContext(); 9 | 10 | CharSequence getText(String resName); 11 | 12 | Bitmap getBitmap(String resName); 13 | 14 | Bitmap getBitmap(String resName, int width, int height); 15 | 16 | int getId(String resName); 17 | 18 | int getStringId(String resName); 19 | 20 | int getLayoutId(String resName); 21 | 22 | int getDrawableId(String resName); 23 | 24 | int getStyleId(String resName); 25 | 26 | int getAnimId(String resName); 27 | 28 | int getColorId(String resName); 29 | 30 | int getDimenId(String resName); 31 | 32 | int getRawId(String resName); 33 | 34 | int getStringArrayId(String resName); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Android-Scrap/backup/ResourceHolder.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.res; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | 7 | import com.heaven7.core.util.ResourceUtil; 8 | 9 | public class ResourceHolder implements ResourceHoldable { 10 | 11 | private Context mContext; 12 | 13 | public ResourceHolder(Context context) { 14 | this.mContext = context; 15 | } 16 | 17 | @Override 18 | public CharSequence getText(String resName){ 19 | return mContext.getResources().getText(getStringId(resName)); 20 | } 21 | 22 | @Override 23 | public Bitmap getBitmap(String resName){ 24 | return BitmapFactory.decodeResource(mContext.getResources(), getDrawableId(resName)); 25 | } 26 | 27 | @Override 28 | public Bitmap getBitmap(String resName,int width,int height){ 29 | Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), getDrawableId(resName)); 30 | if(width <=0 || height<=0){ 31 | return bitmap; 32 | } 33 | return Bitmap.createScaledBitmap(bitmap, width, height, true); 34 | } 35 | 36 | @Override 37 | public int getId(String resName){ 38 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Id); 39 | } 40 | 41 | @Override 42 | public int getStringId(String resName){ 43 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.String); 44 | } 45 | 46 | @Override 47 | public int getLayoutId(String resName){ 48 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Layout); 49 | } 50 | 51 | @Override 52 | public int getDrawableId(String resName){ 53 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Drawable); 54 | } 55 | 56 | @Override 57 | public int getStyleId(String resName){ 58 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Style); 59 | } 60 | 61 | @Override 62 | public int getAnimId(String resName){ 63 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Anim); 64 | } 65 | 66 | @Override 67 | public int getColorId(String resName){ 68 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Color); 69 | } 70 | @Override 71 | public int getDimenId(String resName){ 72 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Dimen); 73 | } 74 | 75 | @Override 76 | public int getRawId(String resName) { 77 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Raw); 78 | } 79 | 80 | @Override 81 | public int getStringArrayId(String resName){ 82 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.StringArray); 83 | } 84 | 85 | @Override 86 | public Context getContext() { 87 | return mContext; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Android-Scrap/bintrayUpload_backup.txt: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.dcendents.android-maven' 2 | apply plugin: 'com.jfrog.bintray' 3 | 4 | // load properties 5 | Properties properties = new Properties() 6 | File localPropertiesFile = project.file("local.properties"); 7 | if(localPropertiesFile.exists()){ 8 | properties.load(localPropertiesFile.newDataInputStream()) 9 | } 10 | File projectPropertiesFile = project.file("project.properties"); 11 | if(projectPropertiesFile.exists()){ 12 | properties.load(projectPropertiesFile.newDataInputStream()) 13 | } 14 | 15 | // read properties 16 | def projectName = properties.getProperty("project.name") 17 | def projectGroupId = properties.getProperty("project.groupId") 18 | def projectArtifactId = properties.getProperty("project.artifactId") 19 | def projectVersionName = android.defaultConfig.versionName 20 | def projectPackaging = properties.getProperty("project.packaging") 21 | def projectSiteUrl = properties.getProperty("project.siteUrl") 22 | def projectGitUrl = properties.getProperty("project.gitUrl") 23 | 24 | def developerId = properties.getProperty("developer.id") 25 | def developerName = properties.getProperty("developer.name") 26 | def developerEmail = properties.getProperty("developer.email") 27 | 28 | def bintrayUser = properties.getProperty("bintray.user") 29 | def bintrayApikey = properties.getProperty("bintray.apikey") 30 | 31 | def javadocName = properties.getProperty("javadoc.name") 32 | 33 | group = projectGroupId 34 | 35 | // This generates POM.xml with proper parameters 36 | install { 37 | repositories.mavenInstaller { 38 | pom { 39 | project { 40 | name projectName 41 | groupId projectGroupId 42 | artifactId projectArtifactId 43 | version projectVersionName 44 | packaging projectPackaging 45 | url projectSiteUrl 46 | licenses { 47 | license { 48 | name 'The Apache Software License, Version 2.0' 49 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 50 | } 51 | } 52 | developers { 53 | developer { 54 | id developerId 55 | name developerName 56 | email developerEmail 57 | } 58 | } 59 | scm { 60 | connection projectGitUrl 61 | developerConnection projectGitUrl 62 | url projectSiteUrl 63 | } 64 | } 65 | } 66 | } 67 | } 68 | 69 | // This generates sources.jar 70 | task sourcesJar(type: Jar) { 71 | from android.sourceSets.main.java.srcDirs 72 | classifier = 'sources' 73 | } 74 | 75 | task javadoc(type: Javadoc) { 76 | source = android.sourceSets.main.java.srcDirs 77 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 78 | } 79 | 80 | // This generates javadoc.jar 81 | task javadocJar(type: Jar, dependsOn: javadoc) { 82 | classifier = 'javadoc' 83 | from javadoc.destinationDir 84 | } 85 | 86 | artifacts { 87 | archives javadocJar 88 | archives sourcesJar 89 | } 90 | 91 | // javadoc configuration 92 | javadoc { 93 | options{ 94 | encoding "UTF-8" 95 | charSet 'UTF-8' 96 | author true 97 | version projectVersionName 98 | links "http://docs.oracle.com/javase/7/docs/api" 99 | title javadocName 100 | } 101 | } 102 | 103 | // bintray configuration 104 | bintray { 105 | user = bintrayUser 106 | key = bintrayApikey 107 | configurations = ['archives'] 108 | pkg { 109 | repo = "maven" 110 | name = projectName 111 | websiteUrl = projectSiteUrl 112 | vcsUrl = projectGitUrl 113 | licenses = ["Apache-2.0"] 114 | publish = true 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Android-Scrap/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.4.2' 10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' 11 | //jcenter 12 | // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' 13 | // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' 14 | //classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' 15 | //classpath 'com.github.dcendents:android-maven-plugin:1.2' 16 | // NOTE: Do not place your application dependencies here; they belong 17 | // in the individual module build.gradle files 18 | } 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | google() 24 | jcenter() 25 | maven { url "https://jitpack.io" } 26 | } 27 | } 28 | ext { 29 | compileSdkVersion = 28 30 | buildToolsVersion = "28.0.3" 31 | 32 | minSdkVersion = 19 33 | targetSdkVersion = 28 34 | } -------------------------------------------------------------------------------- /Android-Scrap/common.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | def androidX_ver = '1.1.0' 3 | 4 | implementation "androidx.appcompat:appcompat:$androidX_ver" 5 | implementation "androidx.recyclerview:recyclerview:$androidX_ver" 6 | 7 | implementation 'com.heaven7.java.base:Java-base:1.2.1' 8 | implementation 'com.github.LightSun:Produce-consume:1.0.2-beta4' 9 | implementation 'com.heaven7.java.visitor:Visitor:1.3.5' 10 | 11 | implementation 'com.github.LightSun:android-ui:1.0.3-x' 12 | implementation 'com.github.LightSun:android-Component:1.1.7-x' 13 | implementation 'com.github.LightSun:Android-Download:1.0.0-beta-x' 14 | implementation 'com.heaven7.core.util:memory:1.0.5' 15 | implementation 'com.github.LightSun:Android-Common-Dialog:1.0.2-x' 16 | implementation 'com.github.LightSun:SuperAdapter:2.1.1-x' 17 | implementation('com.github.LightSun:util-v1:1.1.7-x') { 18 | exclude group: 'com.android.support' 19 | exclude module: 'android-component' 20 | } 21 | implementation('com.github.LightSun.Android-ImagePick:imagepick:2.0.0-beta-x') { 22 | exclude module: 'android-util2' 23 | } 24 | implementation('com.github.LightSun.Android-ImagePick:media:2.0.0-beta-x') { 25 | exclude module: 'android-util2' 26 | } 27 | 28 | implementation('com.github.LightSun:android-util2:1.2.0-x') { 29 | exclude group: "com.heaven7.core.adapter" 30 | exclude group: "com.heaven7.core.util" 31 | exclude module: 'android-component' 32 | } 33 | implementation('com.github.LightSun:android-PullRefreshView:1.1.1-x') { 34 | exclude group: "com.heaven7.core.adapter" 35 | exclude group: "com.heaven7.core.util" 36 | } 37 | implementation 'com.github.LightSun:common-view:1.2.4-x' 38 | } 39 | -------------------------------------------------------------------------------- /Android-Scrap/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | android.useAndroidX=true 20 | # Automatically convert third-party libraries to use AndroidX 21 | android.enableJetifier=true -------------------------------------------------------------------------------- /Android-Scrap/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Android-Scrap/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Aug 01 15:07:23 CST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /Android-Scrap/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /Android-Scrap/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Android-Scrap/lib.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | def androidX_ver = '1.1.0' 3 | 4 | implementation "androidx.appcompat:appcompat:$androidX_ver" 5 | implementation "androidx.recyclerview:recyclerview:$androidX_ver" 6 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" 7 | 8 | implementation 'com.heaven7.java.base:Java-base:1.2.1' 9 | // implementation 'com.github.LightSun:Produce-consume:1.0.2-beta4' 10 | // implementation 'com.heaven7.java.visitor:Visitor:1.3.5' 11 | 12 | // implementation 'com.github.LightSun:android-ui:1.0.3-x' 13 | implementation 'com.github.LightSun:android-Component:1.1.7-x' 14 | // implementation 'com.github.LightSun:Android-Download:1.0.0-beta-x' 15 | implementation 'com.heaven7.core.util:memory:1.0.5' 16 | // implementation 'com.github.LightSun:Android-Common-Dialog:1.0.2-x' 17 | implementation 'com.github.LightSun:SuperAdapter:2.1.7-x' 18 | implementation('com.github.LightSun:util-v1:1.1.7-x') { 19 | exclude module: 'android-component' 20 | } 21 | 22 | implementation('com.github.LightSun:android-util2:1.2.0-x') { 23 | exclude group: "com.heaven7.core.adapter" 24 | exclude group: "com.heaven7.core.util" 25 | exclude module: 'android-component' 26 | } 27 | implementation('com.github.LightSun:android-PullRefreshView:1.1.1-x') { 28 | exclude group: "com.heaven7.core.adapter" 29 | exclude group: "com.heaven7.core.util" 30 | } 31 | implementation 'com.github.LightSun:common-view:1.2.4-x' 32 | } 33 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 19 10 | targetSdkVersion 29 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | 30 | def androidX_ver = '1.1.0' 31 | implementation "androidx.appcompat:appcompat:$androidX_ver" 32 | implementation "androidx.recyclerview:recyclerview:$androidX_ver" 33 | implementation 'com.github.LightSun:SuperAdapter:2.1.7-x' 34 | implementation('com.github.LightSun:util-v1:1.1.7-x') { 35 | exclude module: 'android-component' 36 | } 37 | 38 | implementation 'com.heaven7.java.base:Java-base:1.2.1' 39 | 40 | implementation project(":android-scrap") 41 | } 42 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/src/main/java/com/heaven7/android/style/libsample/OnClickSampleItemListener.java: -------------------------------------------------------------------------------- 1 | package com.heaven7.android.style.libsample; 2 | 3 | import android.content.Context; 4 | 5 | import com.heaven7.android.style.libsample.module.SampleItem; 6 | 7 | public interface OnClickSampleItemListener { 8 | 9 | void onClickSample(Context context, SampleItem item); 10 | } 11 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/src/main/java/com/heaven7/android/style/libsample/SampleConstants.java: -------------------------------------------------------------------------------- 1 | package com.heaven7.android.style.libsample; 2 | 3 | public interface SampleConstants { 4 | 5 | String KEY_LIST = "list"; 6 | String KEY_ITEM_LISTENER = "item_listener"; 7 | String KEY_TITLE = "title"; 8 | } 9 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/src/main/java/com/heaven7/android/style/libsample/module/SampleItem.java: -------------------------------------------------------------------------------- 1 | package com.heaven7.android.style.libsample.module; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.heaven7.adapter.BaseSelector; 7 | 8 | public class SampleItem extends BaseSelector implements Parcelable { 9 | 10 | private String text; 11 | private int id; 12 | 13 | public SampleItem(String text, int id) { 14 | this.text = text; 15 | this.id = id; 16 | } 17 | 18 | public SampleItem(String text) { 19 | this(text, 0); 20 | } 21 | 22 | public String getText() { 23 | return text; 24 | } 25 | public void setText(String text) { 26 | this.text = text; 27 | } 28 | 29 | public int getId() { 30 | return id; 31 | } 32 | public void setId(int id) { 33 | this.id = id; 34 | } 35 | 36 | @Override 37 | public int describeContents() { 38 | return 0; 39 | } 40 | 41 | @Override 42 | public void writeToParcel(Parcel dest, int flags) { 43 | dest.writeString(this.text); 44 | dest.writeInt(this.id); 45 | } 46 | 47 | protected SampleItem(Parcel in) { 48 | this.text = in.readString(); 49 | this.id = in.readInt(); 50 | } 51 | 52 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 53 | @Override 54 | public SampleItem createFromParcel(Parcel source) { 55 | return new SampleItem(source); 56 | } 57 | 58 | @Override 59 | public SampleItem[] newArray(int size) { 60 | return new SampleItem[size]; 61 | } 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/src/main/java/com/heaven7/android/style/libsample/scrap/ListScrapView.java: -------------------------------------------------------------------------------- 1 | package com.heaven7.android.style.libsample.scrap; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.widget.TextView; 6 | 7 | import androidx.recyclerview.widget.LinearLayoutManager; 8 | import androidx.recyclerview.widget.RecyclerView; 9 | 10 | import com.heaven7.adapter.QuickRecycleViewAdapter; 11 | import com.heaven7.adapter.util.ViewHelper2; 12 | import com.heaven7.android.style.libsample.OnClickSampleItemListener; 13 | import com.heaven7.android.style.libsample.R; 14 | import com.heaven7.android.style.libsample.SampleConstants; 15 | import com.heaven7.android.style.libsample.module.SampleItem; 16 | import com.heaven7.java.base.util.Predicates; 17 | import com.heaven7.java.base.util.Reflector; 18 | 19 | import org.heaven7.scrap.core.oneac.BaseScrapView; 20 | 21 | import java.util.ArrayList; 22 | 23 | /** 24 | * need parameters 25 | * @see SampleConstants#KEY_LIST 26 | * @see SampleConstants#KEY_ITEM_LISTENER 27 | * @author heaven7 28 | */ 29 | public class ListScrapView extends BaseScrapView { 30 | 31 | RecyclerView mRv; 32 | 33 | public ListScrapView(Context mContext) { 34 | super(mContext); 35 | } 36 | 37 | @Override 38 | protected int getLayoutId() { 39 | return R.layout.lib_sample_list; 40 | } 41 | 42 | @Override 43 | protected void onAttach() { 44 | super.onAttach(); 45 | ArrayList items = getArguments().getParcelableArrayList(SampleConstants.KEY_LIST); 46 | String cn = getArguments().getString(SampleConstants.KEY_ITEM_LISTENER); 47 | String title = getArguments().getString(SampleConstants.KEY_TITLE); 48 | if(Predicates.isEmpty(items)){ 49 | throw new IllegalStateException("must set sample items"); 50 | } 51 | final OnClickSampleItemListener l; 52 | try { 53 | l = Reflector.from(Class.forName(cn)).newInstance(); 54 | } catch (ClassNotFoundException e) { 55 | throw new RuntimeException(e); 56 | } 57 | TextView tv = getView(R.id.tv_title); 58 | tv.setText(title); 59 | if(title == null){ 60 | tv.setVisibility(View.GONE); 61 | } 62 | 63 | mRv = getView(R.id.rv); 64 | mRv.setLayoutManager(new LinearLayoutManager(getContext())); 65 | mRv.setAdapter(new QuickRecycleViewAdapter(R.layout.lib_sample_item_button, items) { 66 | @Override 67 | protected void onBindData(Context context, int position, final SampleItem item, int itemLayoutId, ViewHelper2 helper) { 68 | helper.setText(R.id.bt, item.getText()) 69 | .setRootOnClickListener(new View.OnClickListener() { 70 | @Override 71 | public void onClick(View v) { 72 | l.onClickSample(getContext(), item); 73 | } 74 | }); 75 | } 76 | }); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/src/main/res/layout/lib_sample_item_button.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/src/main/res/layout/lib_sample_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Android-Scrap/lib_sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | lib_sample 3 | 4 | -------------------------------------------------------------------------------- /Android-Scrap/samples/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Android-Scrap/samples/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply from: '../common.gradle' 3 | 4 | android { 5 | compileSdkVersion rootProject.ext.compileSdkVersion 6 | buildToolsVersion rootProject.ext.buildToolsVersion 7 | 8 | defaultConfig { 9 | applicationId "org.heaven7.scrap.sample" 10 | minSdkVersion rootProject.ext.minSdkVersion 11 | targetSdkVersion rootProject.ext.targetSdkVersion 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | compileOptions { 22 | sourceCompatibility JavaVersion.VERSION_1_8 23 | targetCompatibility JavaVersion.VERSION_1_8 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | //compile 'org.heaven7.scrap:android-scrap:1.1' 30 | 31 | implementation project(':android-scrap') 32 | 33 | api "com.github.bumptech.glide:glide:4.9.0" 34 | def butterknife = '10.0.0' 35 | 36 | implementation "com.jakewharton:butterknife:${butterknife}" 37 | annotationProcessor "com.jakewharton:butterknife-compiler:${butterknife}" 38 | } 39 | -------------------------------------------------------------------------------- /Android-Scrap/samples/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in I:\android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/MainScrapView.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | 6 | import com.heaven7.core.util.Toaster; 7 | 8 | import org.heaven7.scrap.core.oneac.BaseScrapView; 9 | import org.heaven7.scrap.core.oneac.ScrapHelper; 10 | import org.heaven7.scrap.sample.scrapview.TestTransitionScrapView_exit; 11 | 12 | /** 13 | * similar as the Main Activity: so this is used as the Splash scrap view. 14 | * but you must similar set res/raw/scrap_config.properties. 15 | * Created by heaven7 on 2015/8/8. 16 | */ 17 | public class MainScrapView extends BaseScrapView { 18 | 19 | private long start; 20 | 21 | public MainScrapView(Context mContext) { 22 | super(mContext); 23 | } 24 | 25 | public void showToast(String msg) { 26 | Toaster.show(getContext(), msg); 27 | } 28 | 29 | @Override 30 | protected int getLayoutId() { 31 | return R.layout.scrap_main; 32 | } 33 | 34 | @Override 35 | protected boolean onBackPressed() { 36 | if (ScrapHelper.isScrapViewAtBottom(this)) { 37 | if(start == 0){ 38 | start = System.currentTimeMillis(); 39 | showToast("click again to exit MainScrapView!"); 40 | return true; 41 | } 42 | long now = System.currentTimeMillis(); 43 | if (now - start >= 500) { 44 | showToast("click again to exit MainScrapView!"); 45 | start = now; 46 | } else { 47 | ScrapHelper.finishCurrentActivity(); 48 | } 49 | return true; 50 | } 51 | return super.onBackPressed(); 52 | } 53 | 54 | @Override 55 | protected void onAttach() { 56 | //after here i use volley to load image,so must init 57 | 58 | getView(R.id.bt).setOnClickListener(new View.OnClickListener() { 59 | @Override 60 | public void onClick(View v) { 61 | ScrapHelper.beginTransaction() 62 | .addBackAsTop(new TestTransitionScrapView_exit(v.getContext())) 63 | .jump() 64 | .commit(); 65 | } 66 | }); 67 | 68 | //String s = getResources().getDisplayMetrics().toString(); 69 | // ScrapLog.i("getDisplayMetrics",s); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/ScrapApp.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample; 2 | 3 | import android.app.Application; 4 | 5 | 6 | public class ScrapApp extends Application { 7 | 8 | @Override 9 | public void onCreate() { 10 | super.onCreate(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/ScrapLog.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * Created by heaven7 on 2015/8/4. 7 | */ 8 | public class ScrapLog { 9 | 10 | private static final String TAG = "ScrapLog"; 11 | 12 | public static void i(String method,String msg){ 13 | Log.i(TAG,"called [ "+method+" ]: "+msg); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/CommonView.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample.scrapview; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.widget.ImageView; 6 | 7 | import androidx.recyclerview.widget.LinearLayoutManager; 8 | import androidx.recyclerview.widget.RecyclerView; 9 | 10 | import com.bumptech.glide.Glide; 11 | import com.heaven7.adapter.BaseSelector; 12 | import com.heaven7.adapter.QuickRecycleViewAdapter; 13 | import com.heaven7.adapter.util.ViewHelper2; 14 | import com.heaven7.core.util.Toaster; 15 | 16 | import org.heaven7.scrap.core.oneac.BaseScrapView; 17 | import org.heaven7.scrap.sample.R; 18 | import org.heaven7.scrap.util.ArrayList2; 19 | 20 | import java.util.List; 21 | 22 | import butterknife.ButterKnife; 23 | import butterknife.OnClick; 24 | import butterknife.Optional; 25 | 26 | /** 27 | * Created by heaven7 on 2015/8/3. 28 | */ 29 | public class CommonView extends BaseScrapView { 30 | 31 | 32 | public CommonView(Context mContext) { 33 | super(mContext); 34 | } 35 | 36 | @Override 37 | protected int getLayoutId() { 38 | //TODO test KeyEvent. LifeCycle, 39 | return 0; 40 | } 41 | 42 | @Override 43 | protected void onAttach() { 44 | super.onAttach(); 45 | ButterKnife.bind(this, getView()); 46 | showToast("CommonView is attached"); 47 | //set the list view's data 48 | //use QuickAdapter to fast set adapter. 49 | showGirl(); 50 | } 51 | public void showToast(String msg) { 52 | Toaster.show(getContext(), msg); 53 | } 54 | @Optional 55 | @OnClick(R.id.iv_back) 56 | public void onClickBack(View view){ 57 | onBackPressed(); 58 | } 59 | 60 | protected void showGirl() { 61 | addGirlDatas(); 62 | 63 | RecyclerView view = null; //getView(R.id.lv); 64 | view.setLayoutManager(new LinearLayoutManager(getContext())); 65 | view.setAdapter(new QuickRecycleViewAdapter(R.layout.item_girl,mGirlData) { 66 | @Override 67 | protected void onBindData(Context context, int position, GirlData item, int layoutId, ViewHelper2 viewHelper) { 68 | viewHelper.setText(R.id.tv,item.name); 69 | ImageView view = viewHelper.getView(R.id.eniv); 70 | Glide.with(view).load(item.imageUrl).into(view); 71 | } 72 | 73 | }); 74 | } 75 | 76 | private void addGirlDatas() { 77 | String url = "http://images.ali213.net/picfile/pic/2012-06-18/927_h1ali213-page-34.jpg"; 78 | mGirlData.add(new GirlData(url,"girl_1")); 79 | url = "http://www.2cto.com/uploadfile/2013/0407/20130407080828809.jpg"; 80 | mGirlData.add(new GirlData(url,"girl_2")); 81 | url = "http://bagua.40407.com/uploads/allimg/130712/5-130G2141257.jpg"; 82 | mGirlData.add(new GirlData(url,"girl_3")); 83 | url = "http://pic2.52pk.com/files/131213/1283314_094919_1430.jpg"; 84 | mGirlData.add(new GirlData(url,"girl_4")); 85 | } 86 | 87 | private final List mGirlData = new ArrayList2<>(); 88 | 89 | public static class GirlData extends BaseSelector { 90 | public String imageUrl; 91 | public String name; 92 | 93 | public GirlData(String imageUrl, String name) { 94 | this.imageUrl = imageUrl; 95 | this.name = name; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/EntryScrapView.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample.scrapview; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ObjectAnimator; 5 | import android.content.Context; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.TextView; 9 | 10 | import androidx.recyclerview.widget.LinearLayoutManager; 11 | import androidx.recyclerview.widget.RecyclerView; 12 | 13 | import com.heaven7.adapter.BaseSelector; 14 | import com.heaven7.adapter.QuickRecycleViewAdapter; 15 | import com.heaven7.adapter.util.ViewHelper2; 16 | 17 | import org.heaven7.scrap.core.anim.AnimateExecutor; 18 | import org.heaven7.scrap.core.oneac.BaseScrapView; 19 | import org.heaven7.scrap.core.oneac.ScrapHelper; 20 | import org.heaven7.scrap.core.oneac.StackMode; 21 | import org.heaven7.scrap.sample.R; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | import butterknife.BindView; 27 | import butterknife.ButterKnife; 28 | 29 | /** 30 | * Created by heaven7 on 2015/8/3. 31 | */ 32 | public class EntryScrapView extends CommonView { 33 | 34 | // @BindView(R.id.tv_title) 35 | TextView mTv_title; 36 | 37 | /** 38 | * @param mContext the context 39 | */ 40 | public EntryScrapView(Context mContext) { 41 | super(mContext); 42 | } 43 | 44 | @Override 45 | protected void onAttach() { 46 | ButterKnife.bind(this, getView()); 47 | 48 | mTv_title.setText("Scrap_Demos"); 49 | 50 | RecyclerView view = null;//TODO = getView(R.id.lv); 51 | view.setLayoutManager(new LinearLayoutManager(getContext())); 52 | view.setAdapter(new QuickRecycleViewAdapter(R.layout.item_demo, getDatas()) { 53 | @Override 54 | protected void onBindData(Context context, int position, ActionData item, int layoutId, ViewHelper2 helper) { 55 | helper.setText(R.id.bt_action, item.title) 56 | .setText(R.id.tv_desc, item.desc) 57 | .setTag(R.id.bt_action, item.id) 58 | .setOnClickListener(R.id.bt_action, mClickListener); 59 | } 60 | 61 | }); 62 | } 63 | 64 | final View.OnClickListener mClickListener = new View.OnClickListener() { 65 | @Override 66 | public void onClick(View v) { 67 | int id = (int) v.getTag(); 68 | Context context = v.getContext(); 69 | switch (id) { 70 | case 1: 71 | // use transaction to cache? , addback,and jump. 72 | /** 73 | * if you use the same class ScrapView.class to create multi view and want add all of 74 | * them to the default back stack, you must call changeBackStackMode(ArrayList2. 75 | * ExpandArrayList2.Mode.Normal) first. 76 | * Because default setting( contains mode ) of back stack only save 77 | * different view of BaseScrapView. and after call Transaction.commit(). 78 | * the setting( contains mode ) will restore to the default. 79 | */ 80 | Bundle b = new Bundle(); 81 | b.putInt("id", 1); 82 | ScrapHelper.beginTransaction() 83 | .stackMode(StackMode.Normal) 84 | .addBackAsTop(new ScrapView(context)) 85 | .arguments(b) 86 | .jump() 87 | .commit(); 88 | // ScrapHelper.beginTransaction().cache() //if you want cache the view. 89 | break; 90 | case 2: 91 | ScrapHelper.jumpTo(new TestVisivilityScrapView(context)); 92 | break; 93 | case 3: 94 | ScrapHelper.jumpTo(new TestLifeCycleScrapView(context)); 95 | break; 96 | case 4: 97 | 98 | /** 99 | * if you want to set global animate executor, please use ScrapHelper.setAnimateExecutor(animateExecutor); 100 | */ 101 | Bundle b2 = new Bundle(); 102 | b2.putInt("id", 1); 103 | //also use can use #setBundle to carray data 104 | // view2.setBundle(data); 105 | ScrapHelper.beginTransaction() 106 | .stackMode(StackMode.Normal) 107 | .addBackAsTop(new ScrapView(context)) 108 | .animateExecutor(animateExecutor) 109 | .arguments(b2) 110 | .jump() 111 | .commit(); 112 | break; 113 | case 5: 114 | ScrapHelper.jumpTo(new TestKeyEventScrapView(context)); 115 | break; 116 | 117 | case 6: 118 | // ScrapHelper.jumpTo(new TestLoadingScrapView(context)); 119 | } 120 | } 121 | }; 122 | // here use animator to perform animation between two ScrapViews. 123 | private final AnimateExecutor animateExecutor = new AnimateExecutor() { 124 | @Override//use animator 125 | protected byte getType(boolean enter, BaseScrapView previous, BaseScrapView current) { 126 | return TYPE_ANIMATOR; 127 | } 128 | 129 | @Override 130 | protected Animator prepareAnimator(View target, boolean enter, BaseScrapView previous, BaseScrapView current) { 131 | if (!enter) { 132 | //exit 133 | return ObjectAnimator.ofFloat(target, "translationX", 0, 200) 134 | .setDuration(2000); 135 | } else { 136 | // if it is the first BaseScrapView,return null to make it not to animate. 137 | if (previous == null) 138 | return null; 139 | //enter 140 | return ObjectAnimator.ofFloat(target, "translationX", 200, 0) 141 | .setDuration(2000); 142 | } 143 | // AnimatorInflater.loadAnimator(context, id) 144 | } 145 | }; 146 | 147 | private List getDatas() { 148 | List datas = new ArrayList<>(); 149 | String desc = "this is a sample tell you how to listen default back event. how to use Transaction" + 150 | "to cache, add back,jump to it."; 151 | datas.add(new ActionData("Back Stack and Transaction", desc, 1)); 152 | 153 | desc = "this is a sample tell you how to hide or show or toogle visible of top/bottom/middle"; 154 | datas.add(new ActionData("Visibility of ScrapPosition", desc, 2)); 155 | 156 | desc = "this is a sample tell you how to use the Activity's lifecycle callback "; 157 | datas.add(new ActionData("Activity's life cycle", desc, 3)); 158 | 159 | desc = "this is a sample tell you how to use the animation from one BaseScrapView to another. "; 160 | datas.add(new ActionData("ScrapView's Animation", desc, 4)); 161 | 162 | desc = "this is a sample tell you how to register/unregiser the other key event of activity."; 163 | datas.add(new ActionData("Activity's other Key event", desc, 5)); 164 | 165 | desc = "this is a sample tell you how to use the loading view..."; 166 | datas.add(new ActionData("Loading View", desc, 6)); 167 | return datas; 168 | } 169 | 170 | static class ActionData extends BaseSelector { 171 | public ActionData(String title, String desc, int id) { 172 | this.title = title; 173 | this.desc = desc; 174 | this.id = id; 175 | } 176 | String title; 177 | String desc; 178 | int id; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/ScrapView.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample.scrapview; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.heaven7.core.util.ViewHelper; 9 | 10 | import org.heaven7.scrap.core.oneac.ScrapHelper; 11 | import org.heaven7.scrap.core.oneac.StackMode; 12 | import org.heaven7.scrap.sample.R; 13 | import org.heaven7.scrap.sample.ScrapLog; 14 | 15 | import butterknife.BindView; 16 | import butterknife.ButterKnife; 17 | 18 | /** 19 | * Created by heaven7 on 2015/8/3. 20 | */ 21 | public class ScrapView extends CommonView { 22 | 23 | //@BindView(R.id.tv_title) 24 | TextView mTv_title; 25 | @BindView(R.id.tv_middle) 26 | TextView mTv_middle; 27 | 28 | @BindView(R.id.button) 29 | View mBtn; 30 | 31 | public int id; 32 | private boolean mIsLastScrapView; 33 | 34 | public ScrapView(Context mContext) { 35 | super(mContext); 36 | } 37 | 38 | public void setIsLastScrapView(boolean last){ 39 | this.mIsLastScrapView = last; 40 | } 41 | 42 | @Override 43 | protected int getLayoutId() { 44 | return R.layout.scrap_middle_common; 45 | } 46 | 47 | 48 | @Override 49 | protected void onAttach() { 50 | ButterKnife.bind(this, getView()); 51 | 52 | this.id = getArguments() == null ? 0 : getArguments().getInt("id"); 53 | if(id == 4){ 54 | setIsLastScrapView(true); 55 | } 56 | 57 | ScrapLog.i("ScrapView_onAttach","id = " + id); 58 | 59 | mTv_title.setText("ScrapView"+id); 60 | 61 | if(mIsLastScrapView){ 62 | mTv_middle.setText(getResources().getText(R.string.test_back_please_click_back)); 63 | mBtn.setVisibility(View.GONE); 64 | }else{ 65 | mTv_middle.setText(getResources().getText(R.string.test_back_please_click_button)); 66 | mBtn.setVisibility(View.VISIBLE); 67 | } 68 | mBtn.setOnClickListener(new View.OnClickListener() { 69 | @Override 70 | public void onClick(View v) { 71 | /* 72 | * if you use the same class ScrapView.class to create multi view and want add all of 73 | * them to the default back stack, you must call stackMode(StackMode) first. 74 | * Because default setting( contains mode ) of back stack only save 75 | * different view of BaseScrapView. and after call Transaction.commit(). 76 | * the setting( contains mode ) will restore to the default. 77 | */ 78 | Bundle b = new Bundle(); 79 | b.putInt("id",id+1); 80 | 81 | ScrapHelper.beginTransaction().stackMode(StackMode.Normal) 82 | .addBackAsTop(new ScrapView(v.getContext())) 83 | .arguments(b).jump().commit(); 84 | } 85 | }); 86 | } 87 | 88 | @Override 89 | protected void onDetach() { 90 | showToast("ScrapView "+id+ " is detached!"); 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | return "ScrapView{" + 96 | "id=" + id + 97 | '}'; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestKeyEventScrapView.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample.scrapview; 2 | 3 | import android.content.Context; 4 | import android.view.KeyEvent; 5 | import android.view.MotionEvent; 6 | 7 | import org.heaven7.scrap.core.event.ActivityEventAdapter; 8 | import org.heaven7.scrap.core.event.IActivityEventCallback; 9 | import org.heaven7.scrap.core.oneac.ScrapHelper; 10 | import org.heaven7.scrap.sample.ScrapLog; 11 | 12 | /** 13 | * Created by heaven7 on 2015/8/4. 14 | */ 15 | public class TestKeyEventScrapView extends CommonView { 16 | 17 | private IActivityEventCallback callback; 18 | 19 | public TestKeyEventScrapView(Context mContext) { 20 | super(mContext); 21 | } 22 | 23 | @Override 24 | protected void onAttach() { 25 | super.onAttach(); 26 | callback = new ActivityEventAdapter() { 27 | @Override 28 | public boolean onKeyDown(int keyCode, KeyEvent event) { 29 | ScrapLog.i("callback onKeyDown",""); 30 | return super.onKeyDown(keyCode, event); 31 | } 32 | 33 | @Override 34 | public boolean onBackPressed() { 35 | ScrapLog.i("callback onBackPressed",""); 36 | return super.onBackPressed(); //if return true. the all BaseScrapView can't receive back event. 37 | } 38 | 39 | @Override 40 | public boolean onTouchEvent(MotionEvent event) { 41 | ScrapLog.i("callback onTouchEvent",""); 42 | return super.onTouchEvent(event); 43 | } 44 | //...etc methods 45 | }; 46 | ScrapHelper.registerActivityEventCallback(callback); 47 | } 48 | 49 | @Override 50 | protected void onDetach() { 51 | if(callback !=null){ 52 | ScrapHelper.unregisterActivityEventCallback(callback); 53 | callback = null; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestLifeCycleScrapView.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample.scrapview; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.TextView; 9 | 10 | import org.heaven7.scrap.core.lifecycle.ActivityLifeCycleAdapter; 11 | import org.heaven7.scrap.core.lifecycle.IActivityLifeCycleCallback; 12 | import org.heaven7.scrap.core.oneac.ScrapHelper; 13 | import org.heaven7.scrap.sample.R; 14 | import org.heaven7.scrap.sample.ScrapLog; 15 | import org.heaven7.scrap.sample.util.DialogUtil; 16 | 17 | import java.util.Timer; 18 | import java.util.TimerTask; 19 | 20 | import butterknife.ButterKnife; 21 | 22 | /** 23 | * test the stand life cycle of activity. 24 | *
  • Note: Because this view is attached to the Activity. so activity is created. 25 | * some methods will not called.
  • 26 | * if you want register global life cycle callback (.please use 27 | * {@link ScrapHelper#registerActivityLifeCycleCallback(IActivityLifeCycleCallback...)} 28 | * and {@link ScrapHelper#unregisterActivityLifeCycleCallback(IActivityLifeCycleCallback...)} 29 | * it has more methods. 30 | * Created by heaven7 on 2015/8/4. 31 | */ 32 | public class TestLifeCycleScrapView extends CommonView { 33 | 34 | private IActivityLifeCycleCallback callback ; 35 | 36 | public TestLifeCycleScrapView(Context mContext) { 37 | super(mContext); 38 | } 39 | 40 | @Override 41 | protected void onPostInit() { 42 | // offen register it in onAttach. but here we want to see the life cycle . so register in init. 43 | callback = new ActivityLifeCycleAdapter() { 44 | @Override 45 | public void onActivityCreate(Activity activity, Bundle savedInstanceState) { 46 | ScrapLog.i("callback onActivityCreate",""); 47 | } 48 | 49 | @Override 50 | public void onActivityPostCreate(Activity activity, Bundle savedInstanceState) { 51 | ScrapLog.i("callback onActivityPostCreate",""); 52 | } 53 | 54 | @Override 55 | public void onActivityStart(Activity activity) { 56 | ScrapLog.i("callback onActivityStart",""); 57 | } 58 | 59 | @Override 60 | public void onActivityResume(Activity activity) { 61 | ScrapLog.i("callback onActivityResume",""); 62 | } 63 | 64 | @Override 65 | public void onActivityPause(Activity activity) { 66 | ScrapLog.i("callback onActivityPause",""); 67 | } 68 | 69 | @Override 70 | public void onActivityStop(Activity activity) { 71 | ScrapLog.i("callback onActivityStop",""); 72 | } 73 | 74 | @Override 75 | public void onActivityDestroy(Activity activity) { 76 | ScrapLog.i("callback onActivityDestroy",""); 77 | } 78 | @Override 79 | public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { 80 | ScrapLog.i("callback OnActivityResult",""); 81 | } 82 | //....etc methods 83 | }; 84 | // register global life cycle callback 85 | ScrapHelper.registerActivityLifeCycleCallback(callback); 86 | } 87 | 88 | @Override 89 | protected void onAttach() { 90 | // use dialog to help you test it, or else you will see nothing it this. 91 | /* TextView mBt1 = getView(R.id.bt_1); 92 | getView(R.id.bt_1).setOnClickListener(new View.OnClickListener() { 93 | @Override 94 | public void onClick(View v) { 95 | testLifeCycle(); 96 | } 97 | }); 98 | 99 | getView(R.id.bt_2).setVisibility(View.GONE); 100 | getView(R.id.bt_3).setVisibility(View.GONE); 101 | mBt1.setText("Click this button to show auto Dialog and test life cycle");*/ 102 | } 103 | 104 | @Override 105 | protected void onDetach() { 106 | if(callback!=null) { 107 | ScrapHelper.unregisterActivityLifeCycleCallback(callback); 108 | callback = null; 109 | } 110 | } 111 | 112 | private void testLifeCycle() { 113 | DialogUtil.showProgressDialog((Activity) getContext()); 114 | new Timer().schedule(new TimerTask() { 115 | @Override 116 | public void run() { 117 | DialogUtil.dismiss(); 118 | } 119 | }, 2000); 120 | } 121 | 122 | @Override 123 | protected void onActivityCreate(Bundle saveInstanceState) { 124 | ScrapLog.i("onActivityCreate",saveInstanceState.toString()); 125 | } 126 | 127 | @Override 128 | protected void onActivityPostCreate(Bundle saveInstanceState) { 129 | ScrapLog.i("onActivityPostCreate",saveInstanceState.toString()); 130 | } 131 | 132 | @Override 133 | protected void onActivityStart() { 134 | ScrapLog.i("onActivityStart",""); 135 | } 136 | 137 | @Override 138 | protected void onActivityResume() { 139 | ScrapLog.i("onActivityResume",""); 140 | } 141 | 142 | @Override 143 | protected void onActivityPause() { 144 | ScrapLog.i("onActivityPause",""); 145 | } 146 | 147 | @Override 148 | protected void onActivityStop() { 149 | ScrapLog.i("onActivityStop",""); 150 | } 151 | 152 | @Override 153 | protected void onActivityDestroy() { 154 | ScrapLog.i("onActivityDestroy",""); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestTransitionScrapView_enter.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample.scrapview; 2 | 3 | import android.content.Context; 4 | 5 | import org.heaven7.scrap.core.oneac.BaseScrapView; 6 | import org.heaven7.scrap.sample.R; 7 | 8 | public class TestTransitionScrapView_enter extends BaseScrapView { 9 | 10 | public TestTransitionScrapView_enter(Context mContext) { 11 | super(mContext); 12 | } 13 | 14 | @Override 15 | protected int getLayoutId() { 16 | return R.layout.scrap_test_transition_enter; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestTransitionScrapView_exit.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample.scrapview; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | 6 | import org.heaven7.scrap.core.anim.TransitionAnimateExecutor; 7 | import org.heaven7.scrap.core.oneac.BaseScrapView; 8 | import org.heaven7.scrap.core.oneac.ScrapHelper; 9 | import org.heaven7.scrap.sample.R; 10 | 11 | public class TestTransitionScrapView_exit extends BaseScrapView { 12 | 13 | public TestTransitionScrapView_exit(Context mContext) { 14 | super(mContext); 15 | } 16 | 17 | @Override 18 | protected int getLayoutId() { 19 | return R.layout.scrap_test_transition_exit; 20 | } 21 | 22 | @Override 23 | protected void onAttach() { 24 | super.onAttach(); 25 | 26 | getView(R.id.iv_trans).setOnClickListener(new View.OnClickListener() { 27 | @Override 28 | public void onClick(View v) { 29 | ScrapHelper.beginTransaction() 30 | .addBackAsTop(new TestTransitionScrapView_enter(getContext())) 31 | .animateExecutor(new TransitionAnimateExecutor(R.id.iv_trans)) 32 | .jump() 33 | .commit(); 34 | } 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestVisivilityScrapView.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample.scrapview; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | 6 | import org.heaven7.scrap.core.oneac.ScrapHelper; 7 | import org.heaven7.scrap.sample.R; 8 | 9 | /** 10 | * this is sample to test visibility of view which is indicate by the ScrapPosition. 11 | * Created by heaven7 on 2015/8/4. 12 | */ 13 | public class TestVisivilityScrapView extends CommonView { 14 | 15 | public TestVisivilityScrapView(Context mContext) { 16 | super(mContext); 17 | } 18 | 19 | @Override 20 | protected void onPostInit() { 21 | } 22 | 23 | @Override 24 | protected int getLayoutId() { 25 | return R.layout.scrap_middle_test_visibile; 26 | } 27 | 28 | @Override 29 | 30 | protected void onAttach() { 31 | getView(R.id.bt_test1).setOnClickListener(new View.OnClickListener() { 32 | @Override 33 | public void onClick(View v) { 34 | ScrapHelper.setVisibility(true); 35 | } 36 | }); 37 | getView(R.id.bt_test2).setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View v) { 40 | ScrapHelper.setVisibility(false); 41 | } 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/util/DialogUtil.java: -------------------------------------------------------------------------------- 1 | package org.heaven7.scrap.sample.util; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.app.Dialog; 6 | import android.app.ProgressDialog; 7 | import android.content.Context; 8 | import android.content.DialogInterface; 9 | import android.graphics.drawable.ColorDrawable; 10 | import android.util.Log; 11 | import android.view.Gravity; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.view.WindowManager.BadTokenException; 15 | import android.widget.PopupWindow; 16 | 17 | public class DialogUtil { 18 | 19 | private static ProgressDialog sDialog; 20 | private static CharSequence sDefaultMsg; 21 | 22 | public static void dismiss(){ 23 | if(sDialog!=null && sDialog.isShowing()){ 24 | sDialog.dismiss(); 25 | sDialog = null; 26 | } 27 | } 28 | 29 | public static void showProgressDialog(Activity activity){ 30 | if(sDefaultMsg == null) 31 | sDefaultMsg = "loading"; 32 | showProgressDialog(activity,sDefaultMsg); 33 | } 34 | 35 | public static void showProgressDialog(Activity activity,CharSequence content){ 36 | showProgressDialog(activity,"",content); 37 | } 38 | public static void showProgressDialog(Activity activity,CharSequence title, CharSequence content){ 39 | try{ 40 | if(sDialog == null){ 41 | sDialog = ProgressDialog.show(activity, title, content); 42 | sDialog.setCanceledOnTouchOutside(false); 43 | sDialog.setCancelable(false); 44 | sDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { 45 | @Override 46 | public void onCancel(DialogInterface dialog) { 47 | sDialog = null; 48 | } 49 | }); 50 | }else{ 51 | if(sDialog.isShowing()){ 52 | Log.w("showProgressDialog()", "dialog is showing...check?"); 53 | return; 54 | } 55 | } 56 | }catch(BadTokenException e){ 57 | e.printStackTrace(); 58 | } 59 | } 60 | 61 | public static AlertDialog alert(Activity context,String title, String content, 62 | String leftStr,String rightStr, 63 | DialogInterface.OnClickListener leftBtnListener, 64 | DialogInterface.OnClickListener rightBtnListener){ 65 | AlertDialog.Builder builder = new AlertDialog.Builder(context); 66 | builder.setTitle(title); 67 | builder.setMessage(content); 68 | builder.setPositiveButton(leftStr, leftBtnListener); 69 | builder.setNegativeButton(rightStr, rightBtnListener); 70 | AlertDialog dialog = builder.create(); 71 | dialog.setCanceledOnTouchOutside(false); 72 | dialog.setCancelable(false); 73 | dialog.show(); 74 | return dialog; 75 | } 76 | 77 | //@TargetApi(Build.VERSION_CODES.HONEYCOMB) 78 | public static Dialog create(Activity context,int theme,View view){ 79 | /*AlertDialog.Builder builder= null ;builder = new AlertDialog.Builder(context); 80 | 81 | if(view.getParent()!=null){ //be careful when you reuse this view 82 | ((ViewGroup)view.getParent()).removeView(view); 83 | } 84 | builder.setView(view); 85 | AlertDialog d = builder.create(); 86 | d.setCanceledOnTouchOutside(false);*/ 87 | Dialog d = new Dialog(context, theme); 88 | if(view.getParent()!=null){ //be careful when you reuse this view 89 | ((ViewGroup)view.getParent()).removeView(view); 90 | } 91 | d.setContentView(view); 92 | d.setCanceledOnTouchOutside(false); 93 | return d; 94 | } 95 | 96 | //遮罩实现类似dialog 97 | public static PopupWindow popup(Activity context,View view,int width,int height,int animStyle){ 98 | PopupWindow pw = new PopupWindow(context); 99 | pw.setHeight(height); 100 | pw.setWidth(width); 101 | pw.setBackgroundDrawable(new ColorDrawable(0x88222222)); 102 | pw.setOutsideTouchable(true); 103 | pw.setFocusable(true); 104 | pw.setAnimationStyle(animStyle); 105 | if(view.getParent()!=null) 106 | ((ViewGroup)view.getParent()).removeView(view); 107 | pw.setContentView(view); 108 | pw.showAtLocation(context.getWindow().getDecorView(), Gravity.LEFT|Gravity.TOP, 0, 0); 109 | return pw; 110 | } 111 | 112 | /**弹出有动画,自定义样式的dialog*/ 113 | public static Dialog create(Context context,int theme,int animId,int layout){ 114 | //if(layout.getParent()!=null) 115 | //((ViewGroup)layout.getParent()).removeView(layout); 116 | Dialog d = new Dialog(context, theme); 117 | d.getWindow().setWindowAnimations(animId); 118 | d.setContentView(layout); 119 | //d.findViewById(btnId) 120 | d.setCancelable(true); 121 | //d.show(); 122 | return d; 123 | } 124 | 125 | public static void dismiss(Dialog d){ 126 | if(d!=null && d.isShowing()){ 127 | try{ 128 | d.dismiss(); 129 | }catch (BadTokenException e) { 130 | e.printStackTrace(); 131 | } 132 | } 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/res/drawable-hdpi/ic_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/samples/src/main/res/drawable-hdpi/ic_back.png -------------------------------------------------------------------------------- /Android-Scrap/samples/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 |