-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from geeksville/master
0.2.1 merge
- Loading branch information
Showing
35 changed files
with
823 additions
and
269 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -29,6 +29,6 @@ for verbose logging: | |
adb shell setprop log.tag.FA VERBOSE | ||
``` | ||
|
||
Copyright 2018, S. Kevin Hester-Chow, [email protected]. GPL V3 license | ||
Copyright 2019, Geeksville Industries, LLC. GPL V3 license | ||
|
||
|
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
22 changes: 22 additions & 0 deletions
22
app/src/androidTest/java/com/geeksville/mesh/ChannelTest.kt
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,22 @@ | ||
package com.geeksville.mesh | ||
|
||
|
||
import androidx.compose.frames.open | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.geeksville.mesh.model.Channel | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ChannelTest { | ||
@Test | ||
fun channelUrlGood() { | ||
open() // Needed to make Compose think we are inside a Frame | ||
val ch = Channel.emulated | ||
|
||
Assert.assertTrue(ch.getChannelUrl().toString().startsWith(Channel.prefix)) | ||
Assert.assertEquals(Channel(ch.getChannelUrl()), ch) | ||
} | ||
|
||
} |
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
104 changes: 104 additions & 0 deletions
104
app/src/main/java/androidx/ui/fakeandroidview/ComposedView.kt
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,104 @@ | ||
/* | ||
* Copyright 2020 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.ui.fakeandroidview | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.MotionEvent | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT | ||
import androidx.annotation.LayoutRes | ||
import androidx.compose.Composable | ||
|
||
/** | ||
* Composes an Android [View] given a layout resource [resId]. The method handles the inflation | ||
* of the [View] and will call the [postInflationCallback] after this happens. Note that the | ||
* callback will always be invoked on the main thread. | ||
* | ||
* @param resId The id of the layout resource to be inflated. | ||
* @param postInflationCallback The callback to be invoked after the layout is inflated. | ||
*/ | ||
@Composable | ||
// TODO(popam): support modifiers here | ||
fun AndroidView(@LayoutRes resId: Int, postInflationCallback: (View) -> Unit = { _ -> }) { | ||
AndroidViewHolder(postInflationCallback = postInflationCallback, resId = resId) | ||
} | ||
|
||
|
||
private class AndroidViewHolder(context: Context) : ViewGroup(context) { | ||
var view: View? = null | ||
set(value) { | ||
if (value != field) { | ||
field = value | ||
removeAllViews() | ||
addView(view) | ||
} | ||
} | ||
|
||
var postInflationCallback: (View) -> Unit = {} | ||
|
||
var resId: Int? = null | ||
set(value) { | ||
if (value != field) { | ||
field = value | ||
val inflater = LayoutInflater.from(context) | ||
val view = inflater.inflate(resId!!, this, false) | ||
this.view = view | ||
postInflationCallback(view) | ||
} | ||
} | ||
|
||
init { | ||
isClickable = true | ||
} | ||
|
||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | ||
view?.measure(widthMeasureSpec, heightMeasureSpec) | ||
setMeasuredDimension(view?.measuredWidth ?: 0, view?.measuredHeight ?: 0) | ||
} | ||
|
||
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { | ||
view?.layout(l, t, r, b) | ||
} | ||
|
||
override fun getLayoutParams(): LayoutParams? { | ||
return view?.layoutParams ?: LayoutParams(MATCH_PARENT, MATCH_PARENT) | ||
} | ||
|
||
/** | ||
* Implement this method to handle touch screen motion events. | ||
* | ||
* | ||
* If this method is used to detect click actions, it is recommended that | ||
* the actions be performed by implementing and calling | ||
* [.performClick]. This will ensure consistent system behavior, | ||
* including: | ||
* | ||
* * obeying click sound preferences | ||
* * dispatching OnClickListener calls | ||
* * handling [ACTION_CLICK][AccessibilityNodeInfo.ACTION_CLICK] when | ||
* accessibility features are enabled | ||
* | ||
* | ||
* @param event The motion event. | ||
* @return True if the event was handled, false otherwise. | ||
*/ | ||
override fun onTouchEvent(event: MotionEvent?): Boolean { | ||
return super.onTouchEvent(event) | ||
} | ||
} |
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
Oops, something went wrong.