提交 fe0ae2f0 编写于 作者: 门心叼龙's avatar 门心叼龙

code perfect

...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".AsyncTaskActivity"></activity> <activity android:name=".AsyncTaskActivity"></activity>
<activity android:name=".bitmap.test.TestCacheActivity"></activity>
<activity android:name=".TestAsyncTaskActivity" />
<provider <provider
android:name=".provider.MyContentProvider" android:name=".provider.MyContentProvider"
...@@ -26,7 +28,7 @@ ...@@ -26,7 +28,7 @@
android:enabled="true" android:enabled="true"
android:exported="true" /> android:exported="true" />
<activity android:name=".TestServiceActivity" /> <activity android:name=".TestServiceActivity" android:hardwareAccelerated="true"/>
<activity android:name=".WindowManagerActivity" /> <activity android:name=".WindowManagerActivity" />
<activity android:name=".test.view1.SticyLayout2Activity" /> <activity android:name=".test.view1.SticyLayout2Activity" />
<activity android:name=".test.view1.ExpandableListView2Activity" /> <activity android:name=".test.view1.ExpandableListView2Activity" />
...@@ -53,6 +55,7 @@ ...@@ -53,6 +55,7 @@
<activity android:name=".HorizontalScrollViewExActivity" /> <activity android:name=".HorizontalScrollViewExActivity" />
<service android:name=".service.TestService" /> <service android:name=".service.TestService" />
<service android:name=".thread.MyIntentService" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -10,8 +10,17 @@ import android.view.MenuItem; ...@@ -10,8 +10,17 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import com.mxdl.customview.bitmap.DiskLruCache;
import com.mxdl.customview.bitmap.test.TestCacheActivity;
import com.mxdl.customview.test.MainTestActivity; import com.mxdl.customview.test.MainTestActivity;
import com.mxdl.customview.thread.MyAsyncTask;
<<<<<<< HEAD
=======
import java.io.File;
import java.io.IOException;
>>>>>>> 75c4ddacbcbe9ad40d193590d1449f1fd1c37ad1
/** /**
* Description: <MainActivity><br> * Description: <MainActivity><br>
* Author: mxdl<br> * Author: mxdl<br>
...@@ -29,6 +38,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -29,6 +38,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private Button mBtnRectCapture; private Button mBtnRectCapture;
private Button mBtnService; private Button mBtnService;
private Button mBtnAsyncTask; private Button mBtnAsyncTask;
<<<<<<< HEAD
=======
private Button mBtnCache;
>>>>>>> 75c4ddacbcbe9ad40d193590d1449f1fd1c37ad1
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -42,6 +55,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -42,6 +55,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
mBtnRectCapture = findViewById(R.id.btn_capture_rect); mBtnRectCapture = findViewById(R.id.btn_capture_rect);
mBtnService = findViewById(R.id.btn_service); mBtnService = findViewById(R.id.btn_service);
mBtnAsyncTask = findViewById(R.id.btn_async_task); mBtnAsyncTask = findViewById(R.id.btn_async_task);
<<<<<<< HEAD
=======
mBtnCache = findViewById(R.id.btn_cache);
>>>>>>> 75c4ddacbcbe9ad40d193590d1449f1fd1c37ad1
mBtnStickyLayout.setOnClickListener(this); mBtnStickyLayout.setOnClickListener(this);
mBtnHorizontalScrollViewEx.setOnClickListener(this); mBtnHorizontalScrollViewEx.setOnClickListener(this);
mBtnPinnedHeader.setOnClickListener(this); mBtnPinnedHeader.setOnClickListener(this);
...@@ -50,6 +68,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -50,6 +68,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
mBtnRectCapture.setOnClickListener(this); mBtnRectCapture.setOnClickListener(this);
mBtnService.setOnClickListener(this); mBtnService.setOnClickListener(this);
mBtnAsyncTask.setOnClickListener(this); mBtnAsyncTask.setOnClickListener(this);
<<<<<<< HEAD
=======
mBtnCache.setOnClickListener(this);
>>>>>>> 75c4ddacbcbe9ad40d193590d1449f1fd1c37ad1
} }
@Override @Override
...@@ -77,7 +100,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -77,7 +100,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
startActivity(new Intent(this, TestServiceActivity.class)); startActivity(new Intent(this, TestServiceActivity.class));
break; break;
case R.id.btn_async_task: case R.id.btn_async_task:
<<<<<<< HEAD
startActivity(new Intent(this,AsyncTaskActivity.class)); startActivity(new Intent(this,AsyncTaskActivity.class));
=======
startActivity(new Intent(this, TestAsyncTaskActivity.class));
break;
case R.id.btn_cache:
startActivity(new Intent(this, TestCacheActivity.class));
>>>>>>> 75c4ddacbcbe9ad40d193590d1449f1fd1c37ad1
break; break;
} }
......
package com.mxdl.customview;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.util.Log;
import com.mxdl.customview.thread.MyAsyncTask;
import com.mxdl.customview.thread.MyIntentService;
public class TestAsyncTaskActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_async_task);
// new MyAsyncTask("AsyncTask1").execute("");
// new MyAsyncTask("AsyncTask2").execute("");
// new MyAsyncTask("AsyncTask3").execute("");
// new MyAsyncTask("AsyncTask4").execute("");
// new MyAsyncTask("AsyncTask5").execute("");
// HandlerThread handlerThread = new HandlerThread("handler-thread");
// handlerThread.start();
// Handler handler = new Handler(handlerThread.getLooper()){
// @Override
// public void handleMessage(@NonNull Message msg) {
// super.handleMessage(msg);
// Log.v("MYTAG","handleMessage what:"+msg.what+";currThread:"+Thread.currentThread().getName());
// }
// };
//
// handler.sendEmptyMessage(0);
// handler.sendEmptyMessage(1);
new MyAsyncTask("AsyncTask1").executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,"");
new MyAsyncTask("AsyncTask2").executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,"");
new MyAsyncTask("AsyncTask3").executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,"");
// new MyAsyncTask("AsyncTask4").executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,"");
// new MyAsyncTask("AsyncTask5").executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,"");
// Log.v("MYTAG","onCreate:"+Thread.currentThread().getName());
// startService(new Intent(this, MyIntentService.class));
// startService(new Intent(this, MyIntentService.class));
// startService(new Intent(this, MyIntentService.class));
}
}
package com.mxdl.customview.bitmap;
import java.io.FileDescriptor;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
public class ImageResizer {
private static final String TAG = "ImageResizer";
public ImageResizer() {
}
public Bitmap decodeSampledBitmapFromResource(Resources res,
int resId, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
public void test(){
}
public Bitmap decodeSampledBitmapFromFileDescriptor(FileDescriptor fd, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fd, null, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFileDescriptor(fd, null, options);
}
public int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
if (reqWidth == 0 || reqHeight == 0) {
return 1;
}
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
Log.d(TAG, "origin, w= " + width + " h=" + height);
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and
// keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) >= reqHeight
&& (halfWidth / inSampleSize) >= reqWidth) {
inSampleSize *= 2;
}
}
Log.d(TAG, "sampleSize:" + inSampleSize);
return inSampleSize;
}
}
package com.mxdl.customview.bitmap;
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
/**
* Buffers input from an {@link InputStream} for reading lines.
*
* <p>This class is used for buffered reading of lines. For purposes of this class, a line ends
* with "\n" or "\r\n". End of input is reported by throwing {@code EOFException}. Unterminated
* line at end of input is invalid and will be ignored, the caller may use {@code
* hasUnterminatedLine()} to detect it after catching the {@code EOFException}.
*
* <p>This class is intended for reading input that strictly consists of lines, such as line-based
* cache entries or cache journal. Unlike the {@link java.io.BufferedReader} which in conjunction
* with {@link java.io.InputStreamReader} provides similar functionality, this class uses different
* end-of-input reporting and a more restrictive definition of a line.
*
* <p>This class supports only charsets that encode '\r' and '\n' as a single byte with value 13
* and 10, respectively, and the representation of no other character contains these values.
* We currently check in constructor that the charset is one of US-ASCII, UTF-8 and ISO-8859-1.
* The default charset is US_ASCII.
*/
public class StrictLineReader implements Closeable {
private static final byte CR = (byte) '\r';
private static final byte LF = (byte) '\n';
private final InputStream in;
private final Charset charset;
/*
* Buffered data is stored in {@code buf}. As long as no exception occurs, 0 <= pos <= end
* and the data in the range [pos, end) is buffered for reading. At end of input, if there is
* an unterminated line, we set end == -1, otherwise end == pos. If the underlying
* {@code InputStream} throws an {@code IOException}, end may remain as either pos or -1.
*/
private byte[] buf;
private int pos;
private int end;
/**
* Constructs a new {@code LineReader} with the specified charset and the default capacity.
*
* @param in the {@code InputStream} to read data from.
* @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
* supported.
* @throws NullPointerException if {@code in} or {@code charset} is null.
* @throws IllegalArgumentException if the specified charset is not supported.
*/
public StrictLineReader(InputStream in, Charset charset) {
this(in, 8192, charset);
}
/**
* Constructs a new {@code LineReader} with the specified capacity and charset.
*
* @param in the {@code InputStream} to read data from.
* @param capacity the capacity of the buffer.
* @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
* supported.
* @throws NullPointerException if {@code in} or {@code charset} is null.
* @throws IllegalArgumentException if {@code capacity} is negative or zero
* or the specified charset is not supported.
*/
public StrictLineReader(InputStream in, int capacity, Charset charset) {
if (in == null || charset == null) {
throw new NullPointerException();
}
if (capacity < 0) {
throw new IllegalArgumentException("capacity <= 0");
}
if (!(charset.equals(Util.US_ASCII))) {
throw new IllegalArgumentException("Unsupported encoding");
}
this.in = in;
this.charset = charset;
buf = new byte[capacity];
}
/**
* Closes the reader by closing the underlying {@code InputStream} and
* marking this reader as closed.
*
* @throws IOException for errors when closing the underlying {@code InputStream}.
*/
public void close() throws IOException {
synchronized (in) {
if (buf != null) {
buf = null;
in.close();
}
}
}
/**
* Reads the next line. A line ends with {@code "\n"} or {@code "\r\n"},
* this end of line marker is not included in the result.
*
* @return the next line from the input.
* @throws IOException for underlying {@code InputStream} errors.
* @throws EOFException for the end of source stream.
*/
public String readLine() throws IOException {
synchronized (in) {
if (buf == null) {
throw new IOException("LineReader is closed");
}
// Read more data if we are at the end of the buffered data.
// Though it's an error to read after an exception, we will let {@code fillBuf()}
// throw again if that happens; thus we need to handle end == -1 as well as end == pos.
if (pos >= end) {
fillBuf();
}
// Try to find LF in the buffered data and return the line if successful.
for (int i = pos; i != end; ++i) {
if (buf[i] == LF) {
int lineEnd = (i != pos && buf[i - 1] == CR) ? i - 1 : i;
String res = new String(buf, pos, lineEnd - pos, charset.name());
pos = i + 1;
return res;
}
}
// Let's anticipate up to 80 characters on top of those already read.
ByteArrayOutputStream out = new ByteArrayOutputStream(end - pos + 80) {
@Override
public String toString() {
int length = (count > 0 && buf[count - 1] == CR) ? count - 1 : count;
try {
return new String(buf, 0, length, charset.name());
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e); // Since we control the charset this will never happen.
}
}
};
while (true) {
out.write(buf, pos, end - pos);
// Mark unterminated line in case fillBuf throws EOFException or IOException.
end = -1;
fillBuf();
// Try to find LF in the buffered data and return the line if successful.
for (int i = pos; i != end; ++i) {
if (buf[i] == LF) {
if (i != pos) {
out.write(buf, pos, i - pos);
}
pos = i + 1;
return out.toString();
}
}
}
}
}
public boolean hasUnterminatedLine() {
return end == -1;
}
/**
* Reads new input data into the buffer. Call only with pos == end or end == -1,
* depending on the desired outcome if the function throws.
*/
private void fillBuf() throws IOException {
int result = in.read(buf, 0, buf.length);
if (result == -1) {
throw new EOFException();
}
pos = 0;
end = result;
}
}
\ No newline at end of file
package com.mxdl.customview.bitmap;
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
import java.nio.charset.Charset;
/** Junk drawer of utility methods. */
public class Util {
static final Charset US_ASCII = Charset.forName("US-ASCII");
static final Charset UTF_8 = Charset.forName("UTF-8");
private Util() {
}
static String readFully(Reader reader) throws IOException {
try {
StringWriter writer = new StringWriter();
char[] buffer = new char[1024];
int count;
while ((count = reader.read(buffer)) != -1) {
writer.write(buffer, 0, count);
}
return writer.toString();
} finally {
reader.close();
}
}
/**
* Deletes the contents of {@code dir}. Throws an IOException if any file
* could not be deleted, or if {@code dir} is not a readable directory.
*/
static void deleteContents(File dir) throws IOException {
File[] files = dir.listFiles();
if (files == null) {
throw new IOException("not a readable directory: " + dir);
}
for (File file : files) {
if (file.isDirectory()) {
deleteContents(file);
}
if (!file.delete()) {
throw new IOException("failed to delete file: " + file);
}
}
}
static void closeQuietly(/*Auto*/Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (RuntimeException rethrown) {
throw rethrown;
} catch (Exception ignored) {
}
}
}
}
\ No newline at end of file
package com.mxdl.customview.bitmap.test;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;
import android.util.LruCache;
import com.mxdl.customview.bitmap.DiskLruCache;
import com.mxdl.customview.bitmap.ImageResizer;
import com.mxdl.customview.bitmap.test.entity.Person;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
/**
* Description: <Test><br>
* Author: mxdl<br>
* Date: 2019/11/28<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class Test {
private DiskLruCache mDiskLruCache;
public static void main(String[] args) {
//test();
//test2();
}
private void test2() {
File forder = Environment.getDownloadCacheDirectory();
try {
DiskLruCache mDiskLruCache = DiskLruCache.open(Environment.getDownloadCacheDirectory(), 100, 1, 50 * 1024 * 1024);
DiskLruCache.Editor editor = mDiskLruCache.edit("mxdl");
if (editor != null) {
OutputStream outputStream = editor.newOutputStream(0);
if (downloadUrlToStream("mxdl", outputStream)) {
editor.commit();
} else {
editor.abort();
}
mDiskLruCache.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void getFile(String url){
Bitmap bitmap = null;
String key = hashKeyFormUrl(url);
DiskLruCache.Snapshot snapShot = null;
try {
snapShot = mDiskLruCache.get(key);
if (snapShot != null) {
FileInputStream fileInputStream = (FileInputStream)snapShot.getInputStream(0);
FileDescriptor fileDescriptor = fileInputStream.getFD();
bitmap = new ImageResizer().decodeSampledBitmapFromFileDescriptor(fileDescriptor,100,100);
if (bitmap != null) {
//addBitmapToMemoryCache(key,bitmap);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
private String hashKeyFormUrl(String url) {
String cacheKey;
try {
final MessageDigest mDigest = MessageDigest.getInstance("MD5");
mDigest.update(url.getBytes());
cacheKey = bytesToHexString(mDigest.digest());
} catch (NoSuchAlgorithmException e) {
cacheKey = String.valueOf(url.hashCode());
}
return cacheKey;
}
private String bytesToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(0xFF & bytes[i]);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
public boolean downloadUrlToStream(String urlString, OutputStream outputStream) {
HttpURLConnection urlConnection = null;
BufferedOutputStream out = null;
BufferedInputStream in = null;
try {
final URL url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
in = new BufferedInputStream(urlConnection.getInputStream(), 1024 * 1);
out = new BufferedOutputStream(outputStream, 1024 * 1);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
return true;
} catch (IOException e) {
Log.e("MYTAG", "downloadBitmap failed." + e);
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
//MyUtils.close(out);
//MyUtils.close(in);
}
return false;
}
private static void test() {
HashMap<String, String> map1 = new HashMap<>();
map1.put("zhangsan", "zhangsan");
map1.put("lisi", "lisi");
map1.put("wangwu", "wangwu");
Set<Map.Entry<String, String>> entrySet1 = map1.entrySet();
Iterator<Map.Entry<String, String>> iterator1 = entrySet1.iterator();
while (iterator1.hasNext()) {
System.out.println(iterator1.next().toString());
}
System.out.println("==========================================");
LinkedHashMap<String, String> map = new LinkedHashMap<>();
map.put("zhangsan", "zhangsan");
map.put("lisi", "lisi");
map.put("wangwu", "wangwu");
String wangwu = map.get("zhangsan");
String put = map.put("zhaoliu", "zhaoliu");
Set<Map.Entry<String, String>> entrySet = map.entrySet();
Iterator<Map.Entry<String, String>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next().toString());
}
}
}
package com.mxdl.customview.bitmap.test;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.LruCache;
import com.mxdl.customview.R;
import com.mxdl.customview.bitmap.test.entity.Person;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class TestCacheActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_cache);
long maxMemory = Runtime.getRuntime().maxMemory();
Log.v("MYTAG","maxMemary:"+maxMemory+"b");
Log.v("MYTAG","maxMemary:"+maxMemory/(1024)+"kb");
Log.v("MYTAG","maxMemary:"+maxMemory/(1024*1024)+"mb");
LruCache<String, Person> cache = new LruCache<>(3);
cache.put("0",new Person("0,",19));
cache.put("1",new Person("1,",19));
cache.put("2",new Person("2,",19));
Person person = cache.get("0");
//cache.put("3",new Person("3,",19));
LinkedHashMap<String, Person> linkedHashMap = (LinkedHashMap<String, Person>) cache.snapshot();
Set<String> set = linkedHashMap.keySet();
Iterator<String> iterator = set.iterator();
while(iterator.hasNext()){
Log.v("MYTAG",linkedHashMap.get(iterator.next()).toString());
}
Log.v("MYTAG","===============================-------------------------");
LruCache<String,String> map = new LruCache<>(3);
map.put("zhangsan","zhangsan");
map.put("lisi","lisi");
map.put("wangwu","wangwu");
String wangwu = map.get("zhangsan");
String put = map.put("zaholiu", "zhaoliou");
String put1 = map.put("zaholiu", "zhaoliou");
Log.v("MYTAG",put == null ? "null":"not null");
Log.v("MYTAG",put1 == null ? "null":"not null");
Set<Map.Entry<String, String>> entrySet = map.snapshot().entrySet();
Iterator<Map.Entry<String, String>> iterator1 = entrySet.iterator();
while(iterator1.hasNext()){
Log.v("MYTAG",iterator1.next().toString());
}
}
}
package com.mxdl.customview.bitmap.test.entity;
import androidx.annotation.NonNull;
/**
* Description: <Person><br>
* Author: mxdl<br>
* Date: 2019/11/28<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class Person {
public String name;
public int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
@Override
public String toString() {
return "Person{" + "name='" + name + '\'' + ", age=" + age + '}';
}
}
...@@ -17,5 +17,7 @@ public class Test { ...@@ -17,5 +17,7 @@ public class Test {
LinearInterpolator interpolator = new LinearInterpolator(); LinearInterpolator interpolator = new LinearInterpolator();
IntEvaluator intEvaluator = new IntEvaluator(); IntEvaluator intEvaluator = new IntEvaluator();
PopupWindow window = new PopupWindow(); PopupWindow window = new PopupWindow();
} }
} }
...@@ -3,14 +3,25 @@ package com.mxdl.customview.thread; ...@@ -3,14 +3,25 @@ package com.mxdl.customview.thread;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.util.Log; import android.util.Log;
<<<<<<< HEAD
/** /**
* Description: <MyAsyncTask><br> * Description: <MyAsyncTask><br>
* Author: mxdl<br> * Author: mxdl<br>
* Date: 2019/11/24<br> * Date: 2019/11/24<br>
=======
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Description: <MyAsyncTask><br>
* Author: mxdl<br>
* Date: 2019/11/25<br>
>>>>>>> 75c4ddacbcbe9ad40d193590d1449f1fd1c37ad1
* Version: V1.0.0<br> * Version: V1.0.0<br>
* Update: <br> * Update: <br>
*/ */
public class MyAsyncTask extends AsyncTask<String,Integer,String> { public class MyAsyncTask extends AsyncTask<String,Integer,String> {
<<<<<<< HEAD
@Override @Override
protected String doInBackground(String... strings) { protected String doInBackground(String... strings) {
Log.v("MYTAG","doInBackground start;currThread:"+Thread.currentThread().getName()); Log.v("MYTAG","doInBackground start;currThread:"+Thread.currentThread().getName());
...@@ -22,4 +33,29 @@ public class MyAsyncTask extends AsyncTask<String,Integer,String> { ...@@ -22,4 +33,29 @@ public class MyAsyncTask extends AsyncTask<String,Integer,String> {
protected void onPostExecute(String s) { protected void onPostExecute(String s) {
Log.v("MYTAG","onPostExecute start;currThread:"+Thread.currentThread().getName()+";result:"+s); Log.v("MYTAG","onPostExecute start;currThread:"+Thread.currentThread().getName()+";result:"+s);
} }
=======
public String taskName;
public MyAsyncTask(String taskName) {
super();
this.taskName = taskName;
}
@Override
protected String doInBackground(String... strings) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return taskName;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Log.e("MYTAG", "result:"+result);
}
>>>>>>> 75c4ddacbcbe9ad40d193590d1449f1fd1c37ad1
} }
package com.mxdl.customview.thread;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
import androidx.annotation.Nullable;
/**
* Description: <MyIntentService><br>
* Author: mxdl<br>
* Date: 2019/11/25<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class MyIntentService extends IntentService {
public MyIntentService() {
super("MyIntentService");
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
Log.v("MYTAG","onHandleIntent currThread:"+Thread.currentThread().getName());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
...@@ -62,5 +62,14 @@ ...@@ -62,5 +62,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="TestAsyncTask" android:text="TestAsyncTask"
android:textAllCaps="false" /> android:textAllCaps="false" />
<<<<<<< HEAD
=======
<Button
android:id="@+id/btn_cache"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cache"
android:textAllCaps="false" />
>>>>>>> 75c4ddacbcbe9ad40d193590d1449f1fd1c37ad1
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TestAsyncTaskActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".bitmap.test.TestCacheActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册