-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
maning
committed
Jun 4, 2018
1 parent
f945af1
commit 4a94a3e
Showing
7 changed files
with
166 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
libraryzxing/src/main/java/com/google/zxing/client/android/other/ActResultRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.google.zxing.client.android.other; | ||
|
||
import android.app.Activity; | ||
import android.app.FragmentManager; | ||
import android.content.Intent; | ||
|
||
/** | ||
* <pre> | ||
* author : maning | ||
* e-mail : xxx@xx | ||
* time : 2018/06/04 | ||
* desc : | ||
* version: 1.0 | ||
* </pre> | ||
*/ | ||
public class ActResultRequest { | ||
private OnActResultEventDispatcherFragment fragment; | ||
|
||
public ActResultRequest(Activity activity) { | ||
fragment = getEventDispatchFragment(activity); | ||
} | ||
|
||
private OnActResultEventDispatcherFragment getEventDispatchFragment(Activity activity) { | ||
final FragmentManager fragmentManager = activity.getFragmentManager(); | ||
|
||
OnActResultEventDispatcherFragment fragment = findEventDispatchFragment(fragmentManager); | ||
if (fragment == null) { | ||
fragment = new OnActResultEventDispatcherFragment(); | ||
fragmentManager | ||
.beginTransaction() | ||
.add(fragment, OnActResultEventDispatcherFragment.TAG) | ||
.commitAllowingStateLoss(); | ||
fragmentManager.executePendingTransactions(); | ||
} | ||
return fragment; | ||
} | ||
|
||
private OnActResultEventDispatcherFragment findEventDispatchFragment(FragmentManager manager) { | ||
return (OnActResultEventDispatcherFragment) manager.findFragmentByTag(OnActResultEventDispatcherFragment.TAG); | ||
} | ||
|
||
public void startForResult(Intent intent, MNScanCallback callback) { | ||
fragment.startForResult(intent, callback); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
libraryzxing/src/main/java/com/google/zxing/client/android/other/MNScanCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.google.zxing.client.android.other; | ||
|
||
import android.content.Intent; | ||
|
||
/** | ||
* <pre> | ||
* author : maning | ||
* e-mail : xxx@xx | ||
* time : 2018/06/04 | ||
* desc : | ||
* version: 1.0 | ||
* </pre> | ||
*/ | ||
public interface MNScanCallback { | ||
|
||
void onActivityResult(int resultCode, Intent data); | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...c/main/java/com/google/zxing/client/android/other/OnActResultEventDispatcherFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.google.zxing.client.android.other; | ||
|
||
import android.app.Fragment; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.util.SparseArray; | ||
|
||
/** | ||
* <pre> | ||
* author : maning | ||
* e-mail : xxx@xx | ||
* time : 2018/06/04 | ||
* desc : | ||
* version: 1.0 | ||
* </pre> | ||
*/ | ||
public class OnActResultEventDispatcherFragment extends Fragment { | ||
public static final String TAG = "on_act_result_event_dispatcher"; | ||
|
||
private SparseArray<MNScanCallback> mCallbacks = new SparseArray<>(); | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setRetainInstance(true); | ||
} | ||
|
||
public void startForResult(Intent intent, MNScanCallback callback) { | ||
mCallbacks.put(callback.hashCode(), callback); | ||
startActivityForResult(intent, callback.hashCode()); | ||
} | ||
|
||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
|
||
MNScanCallback callback = mCallbacks.get(requestCode); | ||
mCallbacks.remove(requestCode); | ||
|
||
if (callback != null) { | ||
callback.onActivityResult(resultCode, data); | ||
} | ||
} | ||
} |