当前位置: 首页>>代码示例>>Scala>>正文


Scala Uri类代码示例

本文整理汇总了Scala中android.net.Uri的典型用法代码示例。如果您正苦于以下问题:Scala Uri类的具体用法?Scala Uri怎么用?Scala Uri使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Uri类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: PathProvider

//设置package包名称以及导入依赖的类
package com.github.shadowsocks.plugin

import java.io.File

import android.database.MatrixCursor
import android.net.Uri


final class PathProvider private[plugin](baseUri: Uri, cursor: MatrixCursor) {
  private val basePath = baseUri.getPath match {
    case null => ""
    case p => p.stripPrefix("/").stripSuffix("/")
  }

  def addPath(path: String, mode: String = "644"): PathProvider = {
    val stripped = path.stripPrefix("/").stripSuffix("/")
    if (stripped.startsWith(basePath)) cursor.newRow()
      .add(PluginContract.COLUMN_PATH, stripped)
      .add(PluginContract.COLUMN_MODE, mode)
    this
  }
  def addTo(file: File, to: String = "", mode: String = "644"): PathProvider = {
    var sub = to + file.getName
    if (basePath.startsWith(sub)) if (file.isDirectory) {
      sub += '/'
      file.listFiles().foreach(addTo(_, sub, mode))
    } else addPath(sub, mode)
    this
  }
  def addAt(file: File, at: String = "", mode: String = "644"): PathProvider = {
    if (basePath.startsWith(at))
      if (file.isDirectory) file.listFiles().foreach(addTo(_, at, mode)) else addPath(at, mode)
    this
  }
} 
开发者ID:likky,项目名称:shadowsocks_android_build,代码行数:36,代码来源:PathProvider.scala

示例2: getExecutable

//设置package包名称以及导入依赖的类
package com.github.shadowsocks.plugin

import android.content.{ContentProvider, ContentValues}
import android.database.{Cursor, MatrixCursor}
import android.net.Uri
import android.os.{Bundle, ParcelFileDescriptor}


  def getExecutable: String = throw new UnsupportedOperationException

  def openFile(uri: Uri): ParcelFileDescriptor
  override def openFile(uri: Uri, mode: String): ParcelFileDescriptor = {
    assert(mode == "r")
    openFile(uri)
  }

  override def call(method: String, arg: String, extras: Bundle): Bundle = method match {
    case PluginContract.METHOD_GET_EXECUTABLE =>
      val out = new Bundle()
      out.putString(PluginContract.EXTRA_ENTRY, getExecutable)
      out
    case _ => super.call(method, arg, extras)
  }

  // Methods that should not be used
  override def update(uri: Uri, values: ContentValues, selection: String, selectionArgs: Array[String]): Int = ???
  override def insert(uri: Uri, values: ContentValues): Uri = ???
  override def delete(uri: Uri, selection: String, selectionArgs: Array[String]): Int = ???
} 
开发者ID:likky,项目名称:shadowsocks_android_build,代码行数:30,代码来源:NativePluginProvider.scala

示例3: VideoTranscoderTest

//设置package包名称以及导入依赖的类
package com.waz

import java.io.File
import java.util.concurrent.CountDownLatch

import android.content.Context
import android.net.Uri
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.waz.api.AssetFactory.LoadCallback
import com.waz.api.{AssetFactory, AssetForUpload}
import com.waz.bitmap.video.VideoTranscoder
import com.waz.service.ZMessaging
import com.waz.threading.Threading
import org.junit.runner.RunWith
import org.junit.{Assert, Before, Test}

import scala.concurrent.Await
import scala.concurrent.duration._

@RunWith(classOf[AndroidJUnit4])
class VideoTranscoderTest {

  @Before def setUp(): Unit = {
    Threading.AssertsEnabled = false
    ZMessaging.onCreate(context)
  }

  @Test def audioTranscodingFrom8kHz(): Unit = {
    val transcoder = VideoTranscoder(context)
    val out = File.createTempFile("video", ".mp4", context.getCacheDir)

    val future = transcoder(Uri.parse("content://com.waz.test/8khz.mp4"), out, { _ => })

    Assert.assertEquals(out, Await.result(future, 15.seconds))
  }

  @Test def assetLoadingWithNoAudio(): Unit = {
    val latch = new CountDownLatch(1)
    var asset = Option.empty[AssetForUpload]

    AssetFactory.videoAsset(Uri.parse("content://com.waz.test/no_audio.mp4"), new LoadCallback {
      override def onLoaded(a: AssetForUpload): Unit = {
        asset = Some(a)
        latch.countDown()

      }
      override def onFailed(): Unit = {
        println(s"transcode failed")
        latch.countDown()
      }
    })

    latch.await()
    Assert.assertTrue(asset.isDefined)
  }

  def context: Context = instr.getTargetContext
  def instr = InstrumentationRegistry.getInstrumentation
} 
开发者ID:wireapp,项目名称:wire-android-sync-engine,代码行数:61,代码来源:VideoTranscoderTest.scala

示例4: AssetMetaDataTest

//设置package包名称以及导入依赖的类
package com.waz

import android.content.Context
import android.net.Uri
import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.waz.model.AssetMetaData
import com.waz.service.ZMessaging
import com.waz.threading.Threading
import com.waz.utils._
import org.junit.runner.RunWith
import org.junit.{Assert, Before, Test}

import scala.concurrent.Await
import scala.concurrent.duration._

@RunWith(classOf[AndroidJUnit4])
class AssetMetaDataTest {

  @Before def setUp(): Unit = {
    Threading.AssertsEnabled = false
    ZMessaging.onCreate(context)
  }

  @Test def testAudioDurationLoadingFromUri(): Unit = {
    val meta = Await.result(AssetMetaData.Audio(context, Uri.parse("content://com.waz.test/32kbps.m4a")), 5.seconds)

    Assert.assertEquals(309L, meta.fold2(0L, _.duration.getSeconds))
  }

  def context: Context = instr.getTargetContext
  def instr = InstrumentationRegistry.getInstrumentation
} 
开发者ID:wireapp,项目名称:wire-android-sync-engine,代码行数:34,代码来源:AssetMetaDataTest.scala

示例5: MusicPlayer

//设置package包名称以及导入依赖的类
package name.ryanboder.maestroid

import java.io.File

import android.content.Context
import android.media.{MediaPlayer, PlaybackParams}
import android.net.Uri
import org.scaloid.common._


class MusicPlayer(context: Context) extends TagUtil {
  val audioFilePath = "/sdcard/Music/Maestroid.mp3"
  info("Playing " + audioFilePath)

  val audioFile = new File(audioFilePath)
  val player = MediaPlayer.create(context, Uri.fromFile(audioFile))

  def apply(gesture: Gesture): Unit = {
    gesture match {
      case t: Tempo => changeTempo(t)
      case v: Volume => changeVolume(v)
      case g: Gesture => error("Unknown gesture " + g)
    }
  }

  private def changeTempo(tempo: Tempo): Unit = {
    if (!player.isPlaying) {
      player.start()
    }
    info("Setting speed to " + tempo.beatsPerSecond)
    val params = new PlaybackParams()
    params.setSpeed(tempo.beatsPerSecond.toFloat)
    player.setPlaybackParams(params)
  }

  private def changeVolume(v: Volume): Unit = {
    if (!player.isPlaying)
      return
    info("Setting volume to " + v)
    player.setVolume(v.volume.toFloat, v.volume.toFloat)
  }
} 
开发者ID:ryan-boder,项目名称:maestroid,代码行数:43,代码来源:MusicPlayer.scala


注:本文中的android.net.Uri类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。